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

Fix Bootstrap Validation #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
41 changes: 28 additions & 13 deletions src/pristine.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ export default function Pristine(form, config, live){
if (field.errorElements){
return field.errorElements;
}
let errorClassElement = findAncestor(field.input, self.config.classTo);
let errorTextParent = null, errorTextElement = null;
if (self.config.classTo === self.config.errorTextParent){
errorTextParent = errorClassElement;
let errorClassElement = null, errorTextElement = null;
if (self.config.classTo === self.config.errorTextParent) {
errorClassElement = findAncestor(field.input, self.config.classTo);
} else {
errorTextParent = errorClassElement.querySelector('.' + self.config.errorTextParent);
errorClassElement = findAncestor(field.input, self.config.errorTextParent);
}
let errorTextParent = errorClassElement;
if (errorTextParent){
errorTextElement = errorTextParent.querySelector('.' + PRISTINE_ERROR);
if (!errorTextElement){
Expand All @@ -245,9 +245,14 @@ export default function Pristine(form, config, live){
let errorElements = _getErrorElements(field);
let errorClassElement = errorElements[0], errorTextElement = errorElements[1];

if(errorClassElement){
errorClassElement.classList.remove(self.config.successClass);
errorClassElement.classList.add(self.config.errorClass);
if (errorClassElement) {
if (self.config.classTo === self.config.errorTextParent) {
errorClassElement.classList.remove(self.config.successClass);
errorClassElement.classList.add(self.config.errorClass);
} else {
field.input.classList.remove(self.config.successClass);
field.input.classList.add(self.config.errorClass);
}
}
if (errorTextElement){
errorTextElement.innerHTML = field.errors.join('<br/>');
Expand All @@ -269,10 +274,16 @@ export default function Pristine(form, config, live){
function _removeError(field){
let errorElements = _getErrorElements(field);
let errorClassElement = errorElements[0], errorTextElement = errorElements[1];
if (errorClassElement){
// IE > 9 doesn't support multiple class removal
errorClassElement.classList.remove(self.config.errorClass);
errorClassElement.classList.remove(self.config.successClass);
if (errorClassElement) {
if (self.config.classTo === self.config.errorTextParent) {
// IE > 9 doesn't support multiple class removal
errorClassElement.classList.remove(self.config.errorClass);
errorClassElement.classList.remove(self.config.successClass);
} else {
// IE > 9 doesn't support multiple class removal
field.input.classList.remove(self.config.errorClass);
field.input.classList.remove(self.config.successClass);
}
}
if (errorTextElement){
errorTextElement.innerHTML = '';
Expand All @@ -283,7 +294,11 @@ export default function Pristine(form, config, live){

function _showSuccess(field){
let errorClassElement = _removeError(field)[0];
errorClassElement && errorClassElement.classList.add(self.config.successClass);
if (self.config.classTo === self.config.errorTextParent) {
errorClassElement && errorClassElement.classList.add(self.config.successClass);
} else {
errorClassElement && field.input.classList.add(self.config.successClass);
}
}

/***
Expand Down