gpt4 book ai didi

ruby-on-rails-3 - 简单表格标签类

转载 作者:行者123 更新时间:2023-12-01 05:21:32 32 4
gpt4 key购买 nike

我想使用 simple-formbootstrap生成一个有 2 行的水平表格。第一行应该有两个并排的输入 - 一个用于带有一个标签的名字,第二行应该有一个用于电子邮件的输入。我的问题是第一行的标签没有得到 control-label水平表单正确呈现所需的类。但是,所有正确的类都应用于 email field 。

下面是我的代码:

= simple_form_for @order, :url => '/product/process_order', :html => {:class => 'form-horizontal'} do |f|
.form-inputs
.control-group
= f.label :first, "Full and last name"
.controls
= f.input_field :first, :class => "span2", :placeholder => 'First'
= f.input_field :last, :class => "span3" , :placeholder => 'Last'

= f.input :email, :placeholder => 'you@example.com'

生成:
<form accept-charset="UTF-8" action="/product/process_order" class="simple_form form-horizontal" id="new_order" method="post" novalidate="novalidate">
<div class="form-inputs">
<div class="control-group">
<label for="order_first">Full and last name</label>
<div class="controls">
<input class="string required span2" id="order_first" name="order[first]" placeholder="First" size="50" type="text">
<input class="string required span3" id="order_last" name="order[last]" placeholder="Last" size="50" type="text">
</div>
</div>
<div class="control-group email required">
<label class="email required control-label" for="order_email">
<abbr title="required">*</abbr> Email
</label>
<div class="controls"><input class="string email required" id="order_email" name="order[email]" placeholder="you@example.com" size="50" type="email"></div>
</div>
</div>
</form>

最佳答案

在您的 config/initializers/simple_form.rb文件,找到标签类行并将其设置为:

config.label_class = 'control-label'

此外,如果您使用的是 Bootstrap ,您可以在此文件中执行其他一些操作。这也可能对您有所帮助:
SimpleForm.setup do |config|
config.wrappers :my_wrapper, :class => 'control-group',
:hint_class => :field_with_hint, :error_class => :field_with_errors do |b|

b.use :html5

b.use :placeholder

b.optional :maxlength

b.optional :pattern

b.optional :min_max

b.optional :readonly

## Inputs
b.use :label
b.wrapper :my_wrapper, :tag => 'div', :class => 'controls' do |ba|
ba.use :input
ba.use :error, :wrap_with => { :tag => 'span', :class => 'label label-important' }
ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
end
end

config.default_wrapper = :my_wrapper

config.boolean_style = :nested

config.button_class = 'btn'

config.error_notification_tag = :div

config.error_notification_class = 'alert alert-error'

config.label_class = 'control-label'

config.form_class = 'form-horizontal'

config.generate_additional_classes_for = [:wrapper, :label, :input]
config.browser_validations = true
end

关于ruby-on-rails-3 - 简单表格标签类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16289916/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com