【问题标题】:Passing data-mask bootstrap variable into simple_form input?将数据掩码引导变量传递到 simple_form 输入?
【发布时间】:2013-01-21 03:34:24
【问题描述】:

我正在自定义一个 simple_form gem-enabled 表单,我希望它的电话号码字段具有来自http://jasny.github.com/bootstrap/javascript.html#inputmask 的数据掩码

我原来的代码是:

  <%= f.input :phone, :required => true, 
            :input_html => { :maxlength => 14} %>

将类似的东西传递到 f.input 所需的代码是什么?

使用 input_html 和 label_html 之类的东西似乎不起作用。

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap simple-form data-masking


    【解决方案1】:

    在你的表单中试试这个:

    <%= f.input :phone, :required => true, 
                :input_html => { :maxlength => 14, :"data-mask" => "999-999-9999" } %>
    

    另外,假设您运行的是 Rails 3.1+,并且您的 vendor/assets/javascripts 目录中有 jasny 文件,请务必在 app/assets/javascripts/application.js 中包含 bootstrap-inputmask 文件:

    //= require jquery
    //= require jquery_ujs
    //= require bootstrap
    //= require bootstrap-inputmask
    //= require_tree .
    

    【讨论】:

    • 谢谢!我知道这与 input_html 有关...不知道您可以在带有连字符的项目周围使用引号!
    猜你喜欢
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 2017-03-18
    • 2012-11-14
    • 1970-01-01
    • 2022-06-10
    • 2012-09-22
    • 1970-01-01
    相关资源
    最近更新 更多