Jörn Zaefferer schrieb:
> Klaus Hartl schrieb:
>> Paul schrieb:
>>   
>>> What you described is basically what I do, Rick--not because Jorn's plugin
>>> didn't work but because many of my form fields are validated against each
>>> other, and database interaction is required to make that decision. (e.g.,
>>> the validity of field Y depends on the value already entered in field X.)
>>>
>>> Below is the validate function I call onBlur from each input.  It first sets
>>> the field's status icon to a loading spinny, then requests validation from a
>>> CFM file, passing the value of the current field as well as the value of the
>>> dependent criteria, which CF handles (cfswitch/cfcase) depending on which
>>> field is passed.  The callback receives the response and shows either a
>>> success or error icon with a descriptive error attached in a stylish little
>>> error message balloon.
>>>
>>> I don't know if this is the smartest method--I'm pretty new to jQuery
>>> myself--but it has worked very well and provides the flexibility I need.
>>>
>>> HTH,
>>> Paul
>>>     
>> The good thing about such an approach is, that you have to implement 
>> server-side validation anyway - client-side validation can never be more 
>> than an addon to enhance user experience unless you can rely on 
>> JavaScript being enabled. So why not reuse that logic client-side as 
>> well for single fields. You improve the user experience while all logic 
>> is still in place.
>>   
> One of the long-term targets of the validation plugin is to generate as 
> much of the client-side validation rules as possible based on the 
> serverside rules, without additional ajax requests.
> 
> Until that is available in any form, you could use the validation plugin 
> to display your messages (returned from your AJAX request).
> 
> See this demo: 
> http://jquery.bassistance.de/validate/demo-test/ajaxSubmit-intergration-demo.html
> 
> The relevant client code is this:
> 
> var v = $("#form").validate({
>       submitHandler: function(form) {
>               $(form).ajaxSubmit({
>                       dataType: "json",
>                       after: function(result) {
>                               if(result.status) {
>                                       v.showErrors(result.data);
>                               }       
>                       }
>               });
>       }
> });
> 
> In that example, result.data looks like this:
> 
> {'password': 'Your password is wrong (must be foobar).'}
> 
> That way you can use the same setup for displaying both clientside and 
> serverside validation errors. Useful?
> 

Yes, that is already useful! But it still depends on the form to be 
submitted. Would be cool to have single fields validated on blur. That 
would of course be useful for client-side validation as well. Maybe its 
already implemented? I'm not uptodate with that.

-- Klaus


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to