Skip to content
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

add fieldValidClass setting #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion dist/bouncer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* formbouncerjs v1.4.6
* A lightweight form validation script that augments native HTML5 form validation elements and attributes.
* (c) 2019 Chris Ferdinandi
* (c) 2021 Chris Ferdinandi
* MIT License
* http://github.com/cferdinandi/bouncer
*/
Expand Down Expand Up @@ -668,6 +668,28 @@
}));
};

/**
* Add attributes to a valid field
* @param {Node} field The field with the error message
* @param {Object} settings The plugin settings
*/
var addValidAttributes = function (field, settings) {
if (settings.fieldValidClass) {
field.classList.add(settings.fieldValidClass);
}
};

/**
* Remove attributes from a valid field
* @param {Node} field The field with the error message
* @param {Object} settings The plugin settings
*/
var removeValidAttributes = function (field, settings) {
if (settings.fieldValidClass) {
field.classList.remove(settings.fieldValidClass);
}
};

/**
* The plugin constructor
* @param {String} selector The selector to use for forms to be validated
Expand Down Expand Up @@ -707,9 +729,13 @@
// If valid, remove any error messages
if (isValid.valid) {
removeError(field, _settings);
addValidAttributes(field, _settings);
return;
}

// Remove valid attributes
removeValidAttributes(field, _settings);

// Otherwise, show an error message
showError(field, isValid.errors, _settings);

Expand Down
4 changes: 2 additions & 2 deletions dist/bouncer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading