Skip to content

Instantly share code, notes, and snippets.

@ouranos
Forked from n0nick/form.js
Created February 13, 2012 22:49
Show Gist options
  • Save ouranos/1821223 to your computer and use it in GitHub Desktop.
Save ouranos/1821223 to your computer and use it in GitHub Desktop.
Javascript extension for client_side_validations to support Formtastic Bootstrap form builder (v2.0)
clientSideValidations.formBuilders["FormtasticBootstrap::FormBuilder"] = {
add: function (element, settings, message) {
if (element.data('valid') !== false) {
element.data('valid', false);
var $parent = element.closest('.controls');
$parent.parent().addClass('error');
$('<span/>').addClass('help-inline').text(message).appendTo($parent);
} else {
element.parent().find('span.help-inline').text(message);
}
},
remove: function (element, settings) {
var $parent = element.closest('.controls');
$parent.parent().removeClass('error');
$parent.find('span.help-inline').remove();
element.data("valid", true);
element.removeClass('error');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment