开发者

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 .... />
..开发者_如何学JAVA.

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?


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;
}


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 %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜