Skip to content
Snippets Groups Projects

Issue #3292512: Bootstrap 5 : Forms > Checks & radios, added Utility classes...

Closed Issue #3292512: Bootstrap 5 : Forms > Checks & radios, added Utility classes...
All threads resolved!
All threads resolved!
15 files
+ 1913
5
Compare changes
  • Side-by-side
  • Inline
Files
15
+ 44
0
 
/**
 
* @file
 
* Use jquery-validate methods for form validation.
 
*/
 
 
(($, Drupal) => {
 
Drupal.behaviors.ui_suite_bootstrap_validate = {
 
attach() {
 
// check if validator exists, if not, do nothing.
 
if ($.validator === undefined) {
 
return;
 
}
 
// Set default css classes for element (input, normally)
 
// and the label created after to display the error.
 
$("form").validate({
 
errorClass: "error invalid-feedback",
 
validClass: "is-valid",
 
// Modify validator methods to add different css classes
 
// to the element. Default behavior is to add the same
 
// error and valid class to both the element and the error message.
 
highlight(element, validClass) {
 
if (element.type === "radio") {
 
this.findByName(element.name)
 
.addClass("is-invalid error")
 
.removeClass(validClass);
 
} else {
 
$(element).addClass("is-invalid").removeClass(validClass);
 
}
 
},
 
unhighlight(element, errorClass, validClass) {
 
if (element.type === "radio") {
 
this.findByName(element.name)
 
.removeClass(["is-invalid", errorClass])
 
.addClass(validClass);
 
} else {
 
$(element)
 
.removeClass(["is-invalid", errorClass])
 
.addClass(validClass);
 
}
 
},
 
});
 
},
 
};
 
})(jQuery, Drupal);
Loading