teamcfadvance / ValidateThis

An object oriented validation framework for ColdFusion objects
http://www.validatethis.org
44 stars 32 forks source link

Default failure messages should be the same for both server and client side #57

Closed dswitzer closed 12 years ago

dswitzer commented 13 years ago

This is related to issue #56 (https://github.com/ValidateThis/ValidateThis/issues/56).

Bob believes that VT uses the default error messages in jQuery's Validate library when using client-side validation. If this is the case, then I believe the code should be changed so that ValidateThis's failure message is used. This way the errors thrown are identical between the client-side and server-side validation.

bobsilverberg commented 12 years ago

Logic to determine failure messages:

On the server side:

  1. ServerValidator loops over rules calling validate() on the appropriate SRV.
  2. The validate() method in SRV may assign a value to failureMessage in the validation object. 2.1. Inside the SRV, logic sets up the default failure message and places it into the failureMessage property of the Validation object. It uses createDefaultFailureMessage() to deal with the failureMessagePrefix. 2.2. The SRV uses simple text concatenation to create messages that include metadata. If we move to resource bundles we'll need to use placeholders.
  3. If the validation failed, then determineFailureMessage() is called in ServerValidator which uses data from the Validation object and the validation metadata to determine the "true" failure message. This allows for the metadata to override the default failure message.

On the client side:

Looks like each CRS contains a getDefaultFailureMessage() method which holds the text concatenation logic to build the default failure message.

So, it looks like the SRVs and CRSs could be updated to get that information from a resource bundle, rather than from hardcoded text.

bobsilverberg commented 12 years ago
bobsilverberg commented 12 years ago

This has now been implemented in the develop branch and will got out in the 1.0 release