4

I have multiple section is asp.net that submits data in chunk and i want to use jquery validation plugin, but issue is that asp.net wraps everything in form and child forms not wokring right and technically incorrect.

So only alternative is forget about form and implement validation for divs. But all sames i see are using form. As not being not good at jquery i can't figure out how to use this validator on section of page(On div).

Is it possible? or any other good alternative?

Source: http://bassistance.de/jquery-plugins/jquery-plugin-validation/

Sparky
  • 98,165
  • 25
  • 199
  • 285
mamu
  • 12,184
  • 19
  • 69
  • 92
  • Thanks for all responses i have switched application to MVC to get more control and clean html – mamu Aug 06 '09 at 20:03

3 Answers3

1

I am using bassistance jquery plugin that you mentioned above, and it doesnt require form submmission to do validation. it just validated after "on blur" event triggered.

or if you want to validate it manually you can call like : $("#commentForm").validate(); (read on this doc page [http://docs.jquery.com/Plugins/Validation][1])

nightingale2k1
  • 10,095
  • 15
  • 70
  • 96
1

In one of my pages I have a div that is sumitted back via Java and Ajax. Prior to submitting, I validate the individual fields using .validate().element( "#myelement" ); I do it all in javascript though, and don't rely at all on the built in automagic asp controls.

I hate to say it, but that global form issue is your real problem. It's probably not an option, but if it is, look as switching to asp.net MVC.

Russell Steen
  • 6,494
  • 6
  • 38
  • 56
  • Thanks for your response i have switched application to MVC to get more control and clean html – mamu Aug 06 '09 at 20:03
0

Like nightingale2k1 said, you should be able to use that plug-in just fine with a FORM. Here's a quick example that uses a DIV instead:

<div id="pseudoForm">
  <input type="text" name="first_name"/>
  <input type="text" name="last_name"/>
</div>
<script type="text/javascript">
  $("#pseudoForm").validate({
    onfocusout:true,
    rules:{
      first_name:"required",
      last_name:"required"
    });
</script>

Notice how I used "onfocusout:true", which will make the plug-in validate when the user de-selects either element. You'll need to either use something like that, or else hook up your own event (probably in response to a button press) for the validation to be triggered, as the normal trigger (onSubmit) isn't applicable to DIVs.

machineghost
  • 33,529
  • 30
  • 159
  • 234
  • if I do that I get "validator in undefined" on FF, "'settings' is null or not an object" on IE, "Cannot read property 'settings' of undefined" on chrome. What up? – JohnIdol Feb 08 '11 at 17:01
  • Sounds like a problem with the validation plug-in; you'll really need a new SO question, with lots of details and code examples from your specific setup, for anyone to provide meaningful help. – machineghost Feb 09 '11 at 18:18
  • 1
    This isn't an answer, don't know why it is marked as accepted as it wont work. – Tom Chiverton Jan 14 '13 at 13:16
  • 1
    this solution is not working. can anyone provide a working solution. – Ebenezar John Paul Feb 20 '13 at 13:41
  • 1
    -1, This answer needs to be deleted. [The plugin does not work like this](http://jsfiddle.net/Y4h2v/) and the `onfocusout` option is enabled by default. http://jsfiddle.net/Y4h2v/ – Sparky Feb 20 '13 at 18:07