0
votes

I have a form with control group that has multiple input fields, that are displayed in-line. One of these fields has error validations. Unfortunately it is in the middle of the control group and for some crazy design reasons (not my call) I cannot move it to the far right of the group. So I would like the error messages to be appended to the whole control group, not the individual input fields, like it is by default. So my questions are:

1) Is it possible to do in the easy, non-intrusive way eg. only changing configuration files? I tried to meddle with:

config/initializers/simple_form_bootstrap.rb

but the best I could do was:

config.wrappers :none, :tag => false do |b|
  b.use :html5
  b.use :placeholder
  b.use :label
  b.use :input
end
config.wrapper_mappings = { some_input: :none }

and it's almost working, except the error message disappears after I click submit. Other attempts resulted in form not being displayed at all.

2) How can I change the behavior of Simple Form and/or Client Side Validations in a way that I explicitly say which div I want my error message to be displayed? I am aware that this contradicts the idea of errors being shown somewhere around the bad input field, but I really don't want to write custom validation just for this one form.

1

1 Answers

1
votes

I think you should reinstall bootstrap and simple form.

you can try this command:

rails generate simple_form:install --bootstrap

or you can refer to my wrapper config

 config.wrappers :bootstrap, tag: 'div', class: 'control-group', error_class: 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper tag: 'div', class: 'controls' do |ba|
      ba.use :input, class: 'form-control'
      ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
      ba.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
    end   end
  • default wrapper: config.default_wrapper = :bootstrap
  • check attributes in your css files