【问题标题】:Is there a way to set required attribute on text_field_tag?有没有办法在 text_field_tag 上设置必需的属性?
【发布时间】:2013-10-29 12:45:29
【问题描述】:

text_field 中可以执行以下操作来设置required 属性。

true % >

但是,对于text_field_tag,如果我这样做,输出 html 会改为设置 value 属性,这是不正确的。

true % >

输出:

true}" >

text_field_tag 不支持 required 吗?有什么好的解决方法?

【问题讨论】:

    标签: html ruby-on-rails forms


    【解决方案1】:

    试试:text_field_tag(name, value = nil, options = {})

    <%= text_field_tag :street, nil, :required => true %>
    

    当您向助手提供options 时,您必须传递value 参数的值。

    【讨论】:

      【解决方案2】:

      Text field tag

      试试这个:

      <%= text_field_tag :street, '', :required => true %>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-07-13
        • 1970-01-01
        • 1970-01-01
        • 2012-12-25
        • 1970-01-01
        • 2019-03-29
        • 2010-10-24
        相关资源
        最近更新 更多