Skip to content

added feature to use checkbox to force a field to be validated #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2012

Conversation

stevewasiura
Copy link
Contributor

I needed a way to use a checkbox to control if a separate field needed to be validated.

for example, if you wanted to be notified of replies to your comment, you would check a checkbox.
if that checkbox was checked, then the email form field would need to be validated.

the email address form field has the attribute "data-validation-optional" equal to "true"
that allows us to skip validation on that form field if it is blank.

i used the same concept and added a additional attribute to the email form field.
the attribute is named "data-validation-if-checked"
the value of that attribute is the name of the checkbox type field in the form.

the script detects if the form field has that attribute, then gets it's value, finds the form element, determines if it is checked, and sets a var value.

the var value is used in the validateInput function to determine if the element should be forced to validate, appended to optional == 'true' statement

tested in G Chrome , Firefox 13.0.1 & IE 8

@victorjonsson
Copy link
Owner

Great feature Steve! But I will refactor the variable names so they'll conform with the rest of the code. I'll also add the feature to example.html

victorjonsson added a commit that referenced this pull request Jul 4, 2012
added feature to use checkbox to force a field to be validated
@victorjonsson victorjonsson merged commit 7153b7b into victorjonsson:master Jul 4, 2012
@victorjonsson
Copy link
Owner

I made a small change to this feature. You no longer need to have data-validation-optional="true" If you already have data-validation-if-checked="...". I hope you agree on this change.

@stevewasiura
Copy link
Contributor Author

I agree, it is easier for the coder to setup the validation that way. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants