Created
February 14, 2013 10:15
-
-
Save tijmenb/4951779 to your computer and use it in GitHub Desktop.
Bootstrap + Formtastic + client side validations
This file contains 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
/* | |
Client Side Validations + Formtastic + Bootstrap | |
based on: https://github.com/dockyard/client_side_validations-formtastic | |
*/ | |
(function() { | |
ClientSideValidations.formBuilders['FormtasticBootstrap::FormBuilder'] = { | |
add: function(element, settings, message) { | |
var errorElement, wrapper; | |
if (element.data('valid') !== false) { | |
wrapper = element.closest('div.input'); | |
errorElement = $('<span/>', { | |
"class": 'help-inline', | |
text: message | |
}); | |
wrapper.addClass('error'); | |
return wrapper.find('.controls').append(errorElement); | |
} else { | |
return element.parent().find("span.help-inline").text(message); | |
} | |
}, | |
remove: function(element, settings) { | |
var errorElement, wrapper; | |
wrapper = element.closest('div.input.error'); | |
errorElement = wrapper.find("span.help-inline"); | |
wrapper.removeClass('error'); | |
return errorElement.remove(); | |
} | |
}; | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment