-
Notifications
You must be signed in to change notification settings - Fork 101
Bootstrap v3 v4 horizontal form wrapper
Gary edited this page Feb 12, 2018
·
1 revision
An example wrapper for the horizontal_form in Bootstrap v4 (also works with v3)
ClientSideValidations.formBuilders['SimpleForm::FormBuilder'].wrappers.horizontal_form =
add: (element, settings, message) ->
wrapper = element.closest("#{settings.wrapper_tag}.#{settings.wrapper_class.replace(/\ /g, '.')}")
errorWrapper = element.closest("#{settings.wrapper_tag}[class^=\"col-\"]")
errorElement = wrapper.find("#{settings.error_tag}.#{settings.error_class.replace(/\ /g, '.')}")
unless errorElement.length
errorElement = $("<#{settings.error_tag}/>", { class: settings.error_class, text: message })
errorWrapper.append(errorElement)
wrapper.addClass(settings.wrapper_error_class)
errorElement.text(message)
remove: (element, settings) ->
wrapper = element.closest("#{settings.wrapper_tag}.#{settings.wrapper_class.replace(/\ /g, '.')}.#{settings.wrapper_error_class}")
errorWrapper = element.closest("#{settings.wrapper_tag}[class^=\"col-\"]")
errorElement = errorWrapper.find("#{settings.error_tag}.#{settings.error_class.replace(/\ /g, '.')}")
wrapper.removeClass(settings.wrapper_error_class)
errorElement.remove()