简体   繁体   English

将Bootstrap表单帮助程序合并到simple_form中

[英]Incorporating Bootstrap Form Helpers into simple_form

I am trying to implement a select menu with countries , which then filters a select menu with states once a country is selected. 我正在尝试使用国家/地区实现选择菜单,然后在选择国家/地区后使用状态过滤选择菜单。

I use SimpleForm and Bootstrap so the following seems to suit me perfectly: http://vincentlamanna.com/BootstrapFormHelpers/state.html 我使用SimpleForm和Bootstrap,因此以下内容似乎非常适合我: http : //vincentlamanna.com/BootstrapFormHelpers/state.html

I currently use the country_select gem with SimpleForm and my code contains: 我目前将country_select gem与SimpleForm一起使用,并且我的代码包含:

<%= f.input :country, :id => "business_country", :input_html => { :class => "span6" } %>
<%= f.input :state, :input_html => { :class => "span6" } %>

When I included the relevant js files and include the default sample code for Bootstrap Form Helpers the behaviour works as expected but I would like to include it in my SimpleForm so I can save to the database. 当我包含相关的js文件并包含Bootstrap Form Helpers的默认示例代码时,此行为将按预期进行,但我希望将其包含在SimpleForm中,以便将其保存到数据库中。 Here is the default example code that performs correctly: 这是正确执行的默认示例代码:

<select id="countries_states1" class="input-medium bfh-countries" data-country="US"></select>
<select class="input-medium bfh-states" data-country="countries_states1"></select>

Could anyone suggest how to implement this is SimpleForm? 有人可以建议如何实现此功能吗?

Thanks. 谢谢。

Did you follow the instructions on the simple_form gem readme to install with Bootstrap support? 您是否遵循simple_form gem自述文件上的指示进行安装以支持Bootstrap? https://github.com/plataformatec/simple_form#twitter-bootstrap https://github.com/plataformatec/simple_form#twitter-bootstrap

rails generate simple_form:install --bootstrap

I got it to work by finding the correct id of my country select (business_country as seen in my code in my original question) and adding the data-country to the input_html in SimpleForm for the state select. 通过找到正确的国家选择(我在原始问题中的代码中看到的business_country)的正确ID,然后将数据国家添加到SimpleForm的input_html中以选择国家,我可以使其工作。 The code: 编码:

<%= f.input :country, :input_html => { :class => "span6 input-medium bfh-countries"} %>
<%= f.input :state, as: :select, :input_html => {:class => "span6 input-medium bfh-states", 'data-country' => ('business_country') } %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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