简体   繁体   中英

How do I apply a class to the entire form generated by simple_form?

Per the docs I have tried many variations, but none seem to work.

What I would like to happen is this:

<form accept-charset="UTF-8" action="/listings" class="simple_form new_listing form-horizontal" id="new_listing" method="post" novalidate="novalidate">

But when I tried this:

  <%= simple_form_for @listing, :defaults => { :class => 'form-horizontal' } do |f| %>

This is generated:

<form accept-charset="UTF-8" action="/listings" class="simple_form new_listing" id="new_listing" method="post" novalidate="novalidate">

Notice no form-horizontal in the class attribute.

When I try:

  <%= simple_form_for @listing, :defaults => { :wrapper_html => { :class => 'form-horizontal' } } do |f| %>

This is the output generated:

<form accept-charset="UTF-8" action="/listings" class="simple_form new_listing" id="new_listing" method="post" novalidate="novalidate">

It also applies that class to all the elements within the form, eg:

<div class="control-group select optional form-horizontal">

Which is not the outcome I want.

I also tried this:

  <%= simple_form_for @listing, :defaults => { :input_html => { :class => 'form-horizontal' } } do |f| %>

This is the form output it produced:

<form accept-charset="UTF-8" action="/listings" class="simple_form new_listing" id="new_listing" method="post" novalidate="novalidate">

Which looks just like some of the other outputs, but the difference is that it applied that class to all input elements within the form, like this:

<input class="numeric float optional form-horizontal">

So....I have tried everything I can think of, and everything seen in the docs (I think).

What have I missed?

Thanks.

Edit 1:

I also tried the obvious, 'normal' version:

<%= simple_form_for @listing, :class => 'form-horizontal' do |f| %>

That generates this:

<form accept-charset="UTF-8" action="/listings" class="simple_form new_listing" id="new_listing" method="post" novalidate="novalidate">
<%= simple_form_for @listing, :html => { :class => 'form-horizontal' } do |f| %>

那行不通吗

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM