Bug Tracker

Opened 14 years ago

Closed 14 years ago

#3807 closed bug (fixed)

[validate] remote method, custom messages

Reported by: joern Owned by: joern
Priority: major Milestone:
Component: plugin Version:
Keywords: validate remote Cc:
Blocked by: Blocking:

Description (last modified by joern)

It looks like the implementation of the remote method is supposed to support custom messages from the server when using the remote method but because of a trivial bug, they don't work.

This quick change fixes the problem (details below)

915                                     success: function(response) {
916                                             if ( response ) {
917                                                     var submitted = validator.formSubmitted;

915                                     success: function(response) {
916                                             if ( response === true ) {
917                                                     var submitted = validator.formSubmitted;

Because of type coercion, we can only see whether the response is "truthy" or "falsey" from this line. If we take a look at line 924:

924                                                     errors[element.name] =  response || validator.defaultMessage( element, "remote" );

It would seem to be checking the response and assigning that to the error message if it is truthy, but it never can be because of the coercion on line 916. Explicitly checking for true in the response allows us to provide a string as the response and automatically see this appear as the error message. This gives the remote response three possible cases: true: the validation passed false: the validation did not pass - display the default error message / message provided to the validate method <string>: the validation did not pass, display this string as the custom error

Given that it's only possible to have one instance of remote on each field, this is a useful feature for systems that need to do 2 or more distinct checks on a field at the server end.

Change History (2)

comment:1 Changed 14 years ago by joern

Description: modified (diff)

comment:2 Changed 14 years ago by joern

Resolution: fixed
Status: newclosed

Fixed in r6385.

Note: See TracTickets for help on using tickets.