-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bootstrap 4 "input-group-append" validation showing in two lines #762
Comments
Hi, thanks for being part of the Client Side Validations community.
My general advise is to keep things as standard as possible with forms. There is plenty of edge cases, like this one. Rather than customizing the initializer, that is indeed needed for failed server-side validations, please use a custom javascript like the one provided by client_side_validations-simple_form ClientSideValidations.formBuilders['ActionView::Helpers::FormBuilder'] =
add: (element, settings, message) ->
@wrapper(settings.wrapper).add.call(@, element, settings, message)
remove: (element, settings) ->
@wrapper(settings.wrapper).remove.call(@, element, settings)
wrapper: (name) ->
@wrappers[name] || @wrappers.default
wrappers:
default:
add: (element, settings, message) ->
errorTag = settings.error_tag or 'div'
wrapperElement = element.parent()
errorElement = wrapperElement.find("#{errorTag}.invalid-feedback")
unless errorElement.length
errorElement = $("<#{errorTag}/>", { class: 'invalid-feedback', text: message })
hintElement = wrapperElement.find('.form-text')
if hintElement.length
hintElement.before errorElement
else
wrapperElement.append errorElement
element.addClass 'is-invalid'
errorElement.text message
remove: (element, settings) ->
errorTag = settings.error_tag or 'div'
wrapperElement = element.parent()
errorElement = wrapperElement.find("#{errorTag}.invalid-feedback")
element.removeClass 'is-invalid'
errorElement.remove() This also supports hint messages. By the way, you will lose the right border radius on the append button because of a Bootstrap issue. There are workarounds (set Ref:
Hope it helps Closing here |
About the initializer... To show a proper validation message, if validations fail on the server side and you need to use config/initializers/client_side_validations.rb
Form field<div class="form-group">
<%= f.label :price %>
<div class="input-group mb-3">
<%= f.text_field :price, class: "form-control #{@metal.errors[:price].present? ? 'is-invalid': ''}" %>
<div class="input-group-append">
<span class="input-group-text" id="basic-addon2">$</span>
</div>
<%- if @metal.errors[:price].present? %>
<div class="invalid-feedback"><%= @metal.errors[:price].first %></div>
<% end %>
</div>
</div> |
Using Rails 5.2, and Bootstrap 4.3.1 (and no gems like simple form etc).
input-group-append
input-group-prepend
are not working properly.How can we change the initializer settings so this works properly with Bootstrap input-groups?
https://getbootstrap.com/docs/4.3/components/input-group/
#config/initializers/client_side_validations.rb
Related to #617
The text was updated successfully, but these errors were encountered: