manually validate a single field
This commit resolves issue #197 might be helpful as a starting point for issue #126
Adds a public valididateOne method to the validateForm object which allows you to validate a single field manually.
/* Usage /
var valid, field; field = $('[name="name"]).attr('name"); valid = validator.validateOne(field)
if(!valid === true){ / valid === [{name, "name", message="Current error" messages="[Current error, Other errors]"}]
Hi Rick, I added a validationOne method to your code which reuses much of the validateField function to allow a single field to be checked for errors at any time. I didn't yet test it with the depends function, but essentially it doesn't change the existing logic so I'm hoping it might stand up as a useful contribution.
I just found this PR randomly, but it seems to fit my needs. One suggestion, change what the function returns. It returns true if the input is valid and an array if not. This prevents me from doing something like:
isValid = @validator.validateOne(name)
if isValid
clearError
else
displayError
If the field is not valid, it will return an array and hence the else clause is never reached.
Sure you could do something like
errors = @validator.validateOne(name)
if errors == true
clearError
else
displayError
However, that feels awkward to write.
One idea is to run a callback, similar to what _validateForm does.