manually validate a single field#208
manually validate a single field#208BinaryGeometry wants to merge 1 commit intorickharrison:masterfrom
Conversation
This commit resolves issue rickharrison#197 might be helpful as a starting point for issue rickharrison#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 isValid = @validator.validateOne(name)
if isValid
clearError
else
displayErrorIf the field is not valid, it will return an array and hence the Sure you could do something like errors = @validator.validateOne(name)
if errors == true
clearError
else
displayErrorHowever, that feels awkward to write. One idea is to run a callback, similar to what |
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]"}]