teamcfadvance / ValidateThis

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

Prevent JavaScript from throwing error for missing form field #75

Closed dustinmartin closed 12 years ago

dustinmartin commented 12 years ago

When a field was missing on the form, the JavaScript would throw an exception. These small changes should prevent that from happening. The rules simply will not be added if a field is missing. A possible change to this might be to have the missing field logged to the console so the developer knows something might not be right.

bobsilverberg commented 12 years ago

John,

Can you please check these suggested changes and let me know what you think. I recall that we removed a bunch of if statements from the Javascript awhile back (they served a different purpose) for performance reasons so I don't want to just add in new if statements if there might be a concern, or if there's a better way of addressing it.

Thanks, Bob

aliaspooryorik commented 12 years ago

I did remove the check for performance reasons in favour of using contexts to determine which fields are rendered in the JavaScript output. As the jQuery reference in v1.0 is now made before adding the rules the impact of checking to see if the array has length first should be pretty minimal.

I suggest using .length in place of .size().

I'm not sure if a client side field should be ignored by the client side validation if missing and required. For other validation types this makes sense, but if it's required...?