Skip to content

Instantly share code, notes, and snippets.

@bbshih
Forked from ouranos/form.js
Last active December 19, 2015 00:39
Show Gist options
  • Save bbshih/5870021 to your computer and use it in GitHub Desktop.
Save bbshih/5870021 to your computer and use it in GitHub Desktop.
Additional JS to use Formtastic-Bootstrap with Client_Side_Validations
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