sha256 / Pristine

Vanilla javascript form validation micro-library
https://pristine.js.org/
MIT License
410 stars 81 forks source link

Fix Bootstrap Validation #92

Open ryumada opened 1 year ago

ryumada commented 1 year ago

Based on this issue https://github.com/sha256/Pristine/issues/42, I propose this fix.

I've added some if statements to look for if self.config.classTo is the same as self.config.errorTextParent.

...
if (self.config.classTo === self.config.errorTextParent)
...

The main focus is on these lines:

if (self.config.classTo === self.config.errorTextParent) {
    errorClassElement = findAncestor(field.input, self.config.classTo);
} else {
    errorClassElement = findAncestor(field.input, self.config.errorTextParent);
}
let errorTextParent = errorClassElement;

The codes above find errorClassElement based on the values from self.config.classTo and self.config.errorTextParent. If they have the same values, then errorClassElement will take the element from classTo. If not, then errorClassElement will take the element from errorTextParent.

Some of these changes are credited from https://github.com/sha256/Pristine/pull/43 that add or remove valid and invalid classes from input field.

Here, I've created a Bootstrap Form to test out my changes. https://ryumada.github.io/Pristine-test-bootstrap/