Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to Make Client Side Validations Work w/ Twitter Bootstrap & Simple Form
jQuery ($) ->
$("div.control-group").focusout ->
$this = $(this)
if !$this.hasClass("error")
$this.addClass("success")
ClientSideValidations.formBuilders['SimpleForm::FormBuilder'].wrappers.bootstrap =
add: (element, settings, message) ->
wrapper = element.closest(".#{settings.wrapper_class}")
if element.data('valid') != false
wrapper.removeClass('success').addClass(settings.wrapper_error_class)
errorElement = $("<#{settings.error_tag}/>", {
"class": settings.error_class,
text: message
})
wrapper.find(".controls").append(errorElement)
else
wrapper.addClass(settings.wrapper_error_class)
element.parent().find("#{settings.error_tag}.#{settings.error_class}").text(message)
remove: (element, settings) ->
wrapper = element.closest(".#{settings.wrapper_class}.#{settings.wrapper_error_class}")
wrapper.removeClass(settings.wrapper_error_class)
wrapper.addClass('success')
errorElement = wrapper.find("#{settings.error_tag}.#{settings.error_class}")
errorElement.remove()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.