I have two select elements: hours and minutes. If one or both fields are left blank I need an error to appear. I have been using the errorPlacement function to place just one error, but when you correct that one field, the error disappears but the other field is still invalid.
I have tried various combinations of validator.addMethod but there are always issues where both errors will show, or no errors will show etc.
Has anyone faced this issue before? Or does anyone know of a way to detect and handle the errors in the correct way?
Thanks in advance.
I’m not sure which field is required in your example, but you may be looking for dependency expression for jquery Validation. For example, if you wanted to make minutes required only if hours has a value, you would setup the validation like this:
If this is not your desired logic, you will most likely have to create a custom validation method. Is this the logic you had in mind?
For reference:
jQuery Validation Dependency Expression
Edit:
Here is a custom validator:
This will make only 1 error message show up.
Edit #2:
Try this.