Created
July 15, 2013 14:26
-
-
Save ssajous/6000374 to your computer and use it in GitHub Desktop.
Validation utility to be used with Twitter Bootstrap. Displays tooltip on the first invalid element in the form, as well as highlights all invalid elements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ValidationUtility = function() { | |
var validationElements = $('[data-role="validate"]'); | |
var elementCount; | |
validationElements.popover({ | |
placement: 'top' | |
}); | |
validationElements.on('invalid', function() { | |
if (elementCount === 0) { | |
$('#' + this.id).popover('show'); | |
elementCount++; | |
} | |
}); | |
validationElements.on('blur', function() { | |
$('#' + this.id).popover('hide'); | |
}); | |
var validate = function(formSelector) { | |
elementCount = 0; | |
if (formSelector.indexOf('#') === -1) { | |
formSelector = '#' + formSelector; | |
} | |
return $(formSelector)[0].checkValidity(); | |
}; | |
return { | |
validate: validate | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment