I'm using jQuery Validate to validate my on-line things.
it looks like a plugin issue, but my turn-arround was on ajax/param not on the plugin, so i put it on core.
Today i faced a problem, that is: i use remote validation and i needed that all the form is submited to the validation. (this remote validation is like a bridge to the $.ajax)
i have tried this, and of it is not the best deal, because it get the form on ready and don't change when the form change:
- $('#nome').rules('add',
- {
- remote:
- {
- url: 'br/com/evodata/ajax/validaItemNome.php',
- type: 'post',
- data: $('#commentForm').serializeArray()
- }
- });
Then i think about put a function on it.
- $('#nome').rules('add',
- {
- remote:
- {
- url: 'br/com/evodata/ajax/validaItemNome.php',
- type: 'post',
- data: function () {return $('#commentForm').serializeArray()}
- }
- });
And for my surprise, it doesn't work
It don't seems to check if data is a function and call it.
i put an work-around on the param: function that check and parse the data.
- // Serialize an array of form elements or a set of
- // key/values into a query string
- param: function( a, traditional ) {
- var s = [],
- add = function( key, value ) {
- // If value is a function, invoke it and return its value
- value = jQuery.isFunction( value ) ? value() : value;
- s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
- };
- // Set traditional to true for jQuery <= 1.3.2 behavior.
- if ( traditional === undefined ) {
- traditional = jQuery.ajaxSettings.traditional;
- }
- if (jQuery.isFunction(a))
- {
- a = a();
- }
- // If an array was passed in, assume that it is an array of form elements.
- if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
- // Serialize the form elements
- jQuery.each( a, function() {
- add( this.name, this.value );
- });
- } else {
- // If traditional, encode the "old" way (the way 1.3.2 or older
- // did it), otherwise encode params recursively.
- for ( var prefix in a ) {
- buildParams( prefix, a[ prefix ], traditional, add );
- }
- }
- // Return the resulting serialization
- return s.join( "&" ).replace( r20, "+" );
- }
- });
Is someone else with similar problems?
What do you think of that solution?
Is this feature desirable for jQuery ajax?
@marcosfedato
http://marcosfedato.blogspot.com/