0
votes

I'm using the Simple_form gem in a Rails project, which someone was working on before I came on the scene, so I'm not too familiar with it.

Where can I change the position where my error message is displayed? At present they appear underneath the textbox, like so:

enter image description here

Basically, whereabouts in my Rails project is it being told, 'display the error message under the textbox?'

I can see:

<%= f.input :name, :required => true, :label_html => { :class => 'edit_form_titles' }, :error_html => { :class => 'cant_be_blank'} %>

but no matter what I do to that code, it still leaves a space under the text box. I want the message to appear on top, with no space under the text box. There is a file simple_form.rb in my initializers folder, which probably deals with it, but not sure where to look or what to change. It's simple_form 2.0.2.

1

1 Answers

1
votes

I managed to get my errors displaying in the label above the input box.

With the code below I've given my errors a class, which can be formatted as to positioning etc, but there was always a blank div or something under the input box, which put the other input boxes under it out of joint.

<%= f.input :name, :required => true, :label_html => { :class => 'edit_form_titles' }, :error_html => { :class => 'cant_be_blank'} %>

In my initializers/simple_form.rb there was:

  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 |input|
      input.use :input
      input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
      input.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
    end
  end

I changed this to:

  config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper :tag => 'div', :class => 'label-error' do |input|
      b.use :label
      b.use :error, :wrap_with => { :tag => 'span', :class => 'help-block' }
    end
    b.wrapper :tag => 'div', :class => 'controls' do |ba|
      ba.use :input
      ba.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
    end
  end

That got rid of the blank empty space under the input box and I could format my cant_be_blank class so the text appears exactly next to the text in my label.