限制 haml 中输入的最大值
limit the max value for an input in haml
我是使用 RoR 进行编码的新手,我正在使用 Haml,由于我正在做一个学校项目,所以我决定尝试一下。问题是我遇到了一个问题。我的对象中有一个属性 producto
, req_quantity
是客户要求的某个产品的数量。在我看来,我有一个输入框供管理员授权客户请求的数量
.col-xs-2
.text-center
= product.input :auth_quantity, label: false, required: "required"
我想将 :auth_quantity
限制为小于或等于 req_quantity
,因为当前允许的值大于 req_quantity
。
这是我搜索后的第一个问题,但我似乎没有找到答案。
这就是我在 haml 中的做法:
.col-xs-2
.text-center
= product.input :auth_quantity, type: "number", max: "<%= producto.req_quantity %>" label: false, required: "required"
其中 producto.req_quantity
是客户要求的特定产品数量的数值。
所以我基本上是这样解决的。谢谢你的回答,让我想了很多!!
.col-xs-2
.text-center
= producto.input :auth_quantity, input_html: { min: '0', max: product.object.req_quantity, step: 'any' }, label: false, required: "required"
我是使用 RoR 进行编码的新手,我正在使用 Haml,由于我正在做一个学校项目,所以我决定尝试一下。问题是我遇到了一个问题。我的对象中有一个属性 producto
, req_quantity
是客户要求的某个产品的数量。在我看来,我有一个输入框供管理员授权客户请求的数量
.col-xs-2
.text-center
= product.input :auth_quantity, label: false, required: "required"
我想将 :auth_quantity
限制为小于或等于 req_quantity
,因为当前允许的值大于 req_quantity
。
这是我搜索后的第一个问题,但我似乎没有找到答案。
这就是我在 haml 中的做法:
.col-xs-2
.text-center
= product.input :auth_quantity, type: "number", max: "<%= producto.req_quantity %>" label: false, required: "required"
其中 producto.req_quantity
是客户要求的特定产品数量的数值。
所以我基本上是这样解决的。谢谢你的回答,让我想了很多!!
.col-xs-2
.text-center
= producto.input :auth_quantity, input_html: { min: '0', max: product.object.req_quantity, step: 'any' }, label: false, required: "required"