bootstrap-sass和simple_forms的问题



我有一个bug在我的应用程序,但我不知道在哪里看。当我用simple_form格式重构表单时,如:

<%= simple_form_for([@schedule.doctor, @schedule], :html => { :class => 'form-horizontal'}) do |f| %>
    <%= f.label :start_time %>
    <%= f.text_field :start_time %>
    <%= f.label :day %>
    <%= f.select :day, Date::DAYNAMES.zip((0..6).to_a) %>
    <%= f.label :is_available %>
    <%= f.check_box :is_available %>
    <%= f.submit %>
<% end %>

这是它生成的HTML代码(见粗体文本)

<form id="new_schedule" class="simple_form form-horizontal" novalidate="novalidate" method="post" action="/doctors/1/schedules" accept-charset="UTF-8">
**<div style="margin:0;padding:0;display:inline">**
<label class="time optional control-label" for="schedule_start_time">Start time</label>
<input id="schedule_start_time" class="ui-timepicker-input" type="text" size="30" name="schedule[start_time]" autocomplete="off">
<label class="integer optional control-label" for="schedule_day">Day</label>
<select id="schedule_day" name="schedule[day]">
<label class="boolean optional control-label" for="schedule_is_available">Is available</label>
<input type="hidden" value="0" name="schedule[is_available]">
<input id="schedule_is_available" type="checkbox" value="1" name="schedule[is_available]">
<input type="submit" value="Create Schedule" name="commit">
</form>

你知道是什么导致了这个问题吗?

我使用bootstrap-sass与simple_forms

解决方案:

我需要它在simple_form.rb文件中设置config.default_wrapper = :bootstrap,并确保使用simple_forms tags

# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
  config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper :tag => 'div', :class => 'controls' do |ba|
      ba.use :input
      ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
      ba.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
    end
  end
  config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper :tag => 'div', :class => 'controls' do |input|
      input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
        prepend.use :input
      end
      input.use :hint,  :wrap_with => { :tag => 'span', :class => 'help-block' }
      input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
    end
  end
  config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper :tag => 'div', :class => 'controls' do |input|
      input.wrapper :tag => 'div', :class => 'input-append' do |append|
        append.use :input
      end
      input.use :hint,  :wrap_with => { :tag => 'span', :class => 'help-block' }
      input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
    end
  end
  # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
  # Check the Bootstrap docs (http://twitter.github.com/bootstrap)
  # to learn about the different styles for forms and inputs,
  # buttons and other elements.
  config.default_wrapper = :bootstrap
end

相关内容

  • 没有找到相关文章

最新更新