Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert <br> after label tag in simple_form?

Using simple_form, I have a simple input like this:

<%= f.input :email %>

This generates (removed irrelevant parts):

...
  <label>Email</label>
  <input .... />
...

I want the input control to come below the label, so I need a <br/> after </label>:

...
  <label>Email</label>
  <br/>
  <input .... />
...

How do I do the above?

I tried:

inserting a <br/> in config/initializers/simple_form.rb:

config.label_text = lambda { |label, required| "#{required} #{label} <br/>" }

And this generates:

...
  <label>Email<br/></label>  #note the location of <br/>
  <input .... />
...

The <br/> is just before the </label>. Now, this works in terms of showing the input on the next "line", but it just feels "wrong".

Is there some way to do this properly?

like image 913
Zabba Avatar asked Dec 21 '22 17:12

Zabba


2 Answers

Totally agree you should use css to do this as Steve described. But if you really want to, you can still do this by using rails' default form helper like so:

<%= f.label :email %>
<br>
<%= f.text_field :email %>
like image 44
James Chen Avatar answered Jan 12 '23 03:01

James Chen


It's usually better to do this with stylesheet rules than by inserting HTML tags, since the break is a matter of formatting rather than of content. It could be something as simple as...

label {
    display: block;
}
like image 80
Steve Jorgensen Avatar answered Jan 12 '23 05:01

Steve Jorgensen