简单表单输入类型

问题描述 投票:0回答:4

我正在使用简单形式的 gem 来渲染我的表单。我正在尝试将输入字段类型设置为“数字”。此代码不起作用:

f.input :amount, input_html: { type: 'number' }

正确的设置方法是什么?

ruby-on-rails html simple-form
4个回答
22
投票

以下应该有效

f.input :amount, input_html: { type: 'number' }

更干净的方法是:

f.input :amount, as: :numeric

希望有帮助!


10
投票

最简单的方法:

f.input :whatever, as: :numeric

4
投票

尝试:

f.input :amount, as: :integer

0
投票

我在执行此操作时遇到了不同的问题

<%= f.input :password,
            as: :string,
            required: false,
            input_html: { autocomplete: "current-password" }%>

实际的形式只接受整数而不是字符串,因为它应该......我尝试使用 as: :string 但仍然不起作用...有什么想法吗?

© www.soinside.com 2019 - 2024. All rights reserved.