Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ruby on rails - Include two inputs in same LI element in Formtastic

Using formtastic, I have a quantity field and unit field that asks for the quantity of the item and the unit it's measured in.

My problem, is that I would like the unit box to display along side the quantity box. However, because formtastic pust each input in it's own LI element, I can't get them to appear next to each other.

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use an html wrapper for your quantity and unit fields:

<%= form.input :quantity,   :wrapper_html => { :class => 'fl' } %>
<%= form.input :unit,       :wrapper_html => { :class => 'fl' } %>

And in your css (probably formtastic-changes.css), a css float property to float the li. I've added a bit of right margin to give the unit label some room to breathe:

form.formtastic fieldset ol li.fl {float: left; margin-right: 2em;}

You may have to have specific classes or ids for the wrapper_html and fiddle with the css to get your layout and spacing working the way you'd like.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...