Groovy / Grails浮点值和HTML5数字输入 [英] Groovy/Grails Float value and HTML5 number input

查看:94
本文介绍了Groovy / Grails浮点值和HTML5数字输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Groovy / Grails 2.0中,我有一个带有Float变量的域(例如Float weight = 25.28)。当Grails使用相应的数字输入字段生成表单时,验证会报告25.28的值,并且只接受一个int值。有人可以说明这是怎么回事?
提前致谢。

编辑:
在Gails域对象(Double和BigDecimal为了参数):

 双重重量= 350.26; 
BigDecimal width = 86.1;

生成的html:

 < input id =weighttype =numbervalue =350.26required =name =weight> 
< input id =widthtype =numbervalue =86.1required =name =width>

...将我们的FF 7与这些数值进行比较,Chrome会给我无效值并只接受整数。
关于我缺少的任何想法?

解决方案

如果您使用'grails generate-all'_form .gsp文件,然后更新生成的_form.gsp输入元素以添加step =0.001或step =0.1或step =any或类似内容。

http://code.google.com/p/chromium/issues/detail?id=44116

获取此更新到所有生成的_form.gsp文件的一种方法是运行'grails install-templates',然后编辑src / templates / scaffolding / renderEditor。模板renderNumberEditor方法并将step =any添加到每个

In Groovy/Grails 2.0 I've got a domain with Float variable ( Float weight = 25.28 for example ). When Grails generates form with corresponding number input field, validation complains about the 25.28 value and will only accept an int value. Could someone illuminate what's going on with that? Thanks in advance.

EDIT: In Gails domain object(Double and BigDecimal for the sake of argument):

   Double weight = 350.26;
   BigDecimal width = 86.1;

Generated html:

<input id="weight" type="number" value="350.26" required="" name="weight">
<input id="width" type="number" value="86.1" required="" name="width">

... turns our FF 7 is fine with those numeric values and Chrome gives me "Invalid Value" and only accepts integers. Any idea on what I'm missing?

解决方案

If you're using 'grails generate-all' _form.gsp files then update the generated _form.gsp input element to add step="0.001" or step="0.1" or step="any" or the like.

http://code.google.com/p/chromium/issues/detail?id=44116

One approach to get this update into all generated _form.gsp files is to run 'grails install-templates' then edit src/templates/scaffolding/renderEditor.template renderNumberEditor method and add step="any" to each

这篇关于Groovy / Grails浮点值和HTML5数字输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆