【问题标题】:Rails and simple form: novalidate attribute doesn't workRails 和简单形式:novalidate 属性不起作用
【发布时间】:2013-10-11 14:39:38
【问题描述】:

我的登录页面(使用简单表单构建)默认添加 html 属性,用于对 chrome 无法识别的电子邮件输入进行浏览器验证并显示“请匹配请求的格式”。

可能是 Chrome 错误(在 firefox 上有效),因此尝试使用简单的表单配置禁用浏览器验证 SimpleForm.html5SimpleForm.browser_validations(默认为 false),重新启动 rails 但保持相同的输入:

<input autofocus="autofocus" class="string email optional form-control
input-xlarge" id="customer_email" maxlength="255"
name="customer[email]" pattern="\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z"
size="255" type="email">

也尝试添加表单html: {novalidate: true},输出相同

终于尝试在input_filed上添加:novalidate =&gt; true,html输出变为:

<input autofocus="autofocus" class="string email optional form-control
input-xlarge" id="customer_email" maxlength="255"
name="customer[email]" pattern="\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z"
size="255" type="email" novalidate="novalidate">

但存在浏览器验证和 chrome 错误。

有什么解决办法吗?

PS:使用 Bootstrap,登录表单来自 Devise 资源。

【问题讨论】:

    标签: ruby-on-rails html simple-form


    【解决方案1】:

    您可以从导致问题的输入元素中删除模式属性。您只需在输入字段中设置pattern: false

    所以您的输入字段可能如下所示:

    <%= f.input_field :email, type: 'email', required: true, autofocus: true, class: 'form-control', pattern: false %>
    

    nil 不起作用;它必须是false。)

    这在 Rails 4 中对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-04
      • 2017-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多