Details
-
Type:
Bug
-
Status:
In Progress
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 2.0-RC3, 2.0 final, 2.0.1
-
Fix Version/s: 2.3-M2
-
Component/s: Converters, Scaffolding, TagLib, View technologies
-
Labels:
-
Environment:grails 2.0.0.RC3, kubuntu 10.04.3 LTS, jvm 1.6.26
Description
There are two Problems:
1)
The scale is not respected.
The html5 number input type doesn't allow decimal points by default (needs step attribute), even in US locale, in Chrome. (oops)
2)
When setting the scale-constraints for a BigDecimal higher then 3 it is not reflected in the views.
It configures the scale value correctly in the DB-Scheme. Even the create-view works correct. Correct value is persisted in DB.
But after that, only the first 3 decimal places are shown. Even on the edit page everything more then the 3 decimal places are omitted.
The result is that you loose information!
--------
Whats adds up to this problem is that when you use html5 capable browsers like chrome or opera you won't
be able to type in any decimal places. They interpret the <input type="number" as an Integer value. (As mentioned in 1) it needs the step attribute)
The behaviour is double confirmed on the mailing list http://grails.1312388.n4.nabble.com/Grails-2-0-0-RC1-BigDecimals-and-Scaffolding-td3943888.html + I'll attach a example app scaffolding the following simple domain class.
package scaleprob class Calc { BigDecimal result static constraints = { result (scale:8) } }
Cheers,
Kosta
-
Hide
- scaleProb-bug-report-07122011.zip
- 07/Dec/11 2:43 PM
- 28 kB
- Konstantinos Kostarellis
-
- grails-app/.../ApplicationResources.groovy 0.1 kB
- grails-app/conf/BootStrap.groovy 0.1 kB
- grails-app/conf/BuildConfig.groovy 2 kB
- grails-app/conf/Config.groovy 4 kB
- grails-app/conf/DataSource.groovy 1 kB
- grails-app/conf/UrlMappings.groovy 0.2 kB
- grails-app/conf/WebXmlConfig.groovy 2 kB
- grails-app/conf/spring/resources.groovy 0.0 kB
- grails-app/.../CalcController.groovy 3 kB
- grails-app/domain/scaleprob/Calc.groovy 0.1 kB
- grails-app/i18n/messages.properties 3 kB
- grails-app/.../messages_cs_CZ.properties 3 kB
- grails-app/i18n/messages_da.properties 3 kB
- grails-app/i18n/messages_de.properties 4 kB
- grails-app/i18n/messages_es.properties 3 kB
- grails-app/i18n/messages_fr.properties 2 kB
- grails-app/i18n/messages_it.properties 2 kB
- grails-app/i18n/messages_ja.properties 4 kB
- grails-app/i18n/messages_nl.properties 3 kB
- grails-app/.../messages_pt_BR.properties 3 kB
- grails-app/.../messages_pt_PT.properties 3 kB
- grails-app/i18n/messages_ru.properties 4 kB
- grails-app/i18n/messages_sv.properties 3 kB
- grails-app/i18n/messages_th.properties 6 kB
- grails-app/.../messages_zh_CN.properties 2 kB
- grails-app/views/calc/_form.gsp 0.4 kB
- grails-app/views/calc/create.gsp 2 kB
- grails-app/views/calc/edit.gsp 2 kB
- grails-app/views/calc/list.gsp 2 kB
- grails-app/views/calc/show.gsp 2 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
For my understanding, is(was?) the problem not with any scale? I have a scale of 2 (which should the default for BigDecimal), and the HTML5 number type input generated for g:field does not have step="0.01" generated. Or should I create a separate issue (I could then attach a specific, actual, test case). I think the fix implemented here consists in adding step="any", but this is not the best use of the HTML5 number type input.
While testing, I realize that min and max are not used either. (NB this is not related to scaffolding. I want to minimize code to maintain. I don't want hard coded min, max and step in my views)...?
Unfortunately there is still a flaw i found (checked with grails 2.1 rc2 + Firefox 12.0)
If you use e.g. a German locale (?lang=de) which swaps ',' for '.' in numbers, then everything
seems to work fine (create, list, show) until you try to edit an entry.
On the edit form the input field is pre-filled with the number ignoring the German local
using a '.' instead of a ',', which obviously leads to errors on sending the form.
On a validation Round-Trip with validation errors attached (e.g. from other input-fields) the number is also wrongly formatted (not respecting locale, swapping ',' with '.').
I don't think this is a browser-specific flaw, but I can't really tell.
I'm just mentioning this because Chrome shows up with more/other problems if html5/type="number" is used. But this is more of a Chrome problem.
------
Another thing to mention is that <g:fieldValue /> (used on show & list - pages) still
shows numbers rounded to the first 3 decimal. Don't know if this always the desired behavior.
Is there a way/tag to control this ?
Slightly off-topic but still interesting (IMO).
I researched some of the behavior of Chrome.
E.g. using german locale and the following input-field.
<input type="number" name="result" step="0.0001" required="" id="result" />
It will show something like 2,5 on the input-field but will send 2.5 on the post-request.
A none html5/type=number field would have send 2,5 - which is the grails expected value
for a german localed request. The result is that grails thinks of the input-value as the number 25 !
Is this really the html5 specified behavior - sending locale unaware values into the request?
Thinking of this makes a transition to html5-number-inputfields a big pain, as some browsers including FF are not interpreting type="number" yet. What a mess!
----------
That's just a side-note: Unlike the previous comment which describes a flaw that really needs some fixing.
I'm reopening this issue. The problems with using `type="number"` in locales that use a comma as a decimal separator are significant especially cross-browser. I think the best thing to do is continue to use `type="number"` for integer types and revert to `type="text"` for decimal types
I agree, this is the best way to go @ least for the present time.
About the html5 component I had some discussion here http://code.google.com/p/chromium/issues/detail?id=44116 << which obviously is not the right place, but still is an interesting discussion on the topic.
Finally I suggested an additional parameter (localized="true") to ease the transition. But even if something similar would get picked up it will take a long time till browser vendors implement such things.
Until then IMO it seems that the new html5 component for floats basically can only be used in single language U.S.-localized Apps (or other Locales that uses the "." as delimiter).
@Robert thnx for reopening and putting in the effort to get this straight.
Can you take a look at the amended `renderEditor.template` I've just pushed here: https://github.com/grails/grails-core/commit/6d835b2c3302fa8c00d302b9158b5b49b39f7529
You should be able to just copy that file into your project. Let me know if it now works better and I'll close the issue.
It's close ... almost working ... but it re-introduces the problem that the values are cut to 3 floating-point-digits when going to the edit page.
e.g. domain Bar
—
package demo
class Bar {
BigDecimal someFloat
String text
static constraints =
{ someFloat(min:-10.0, scale: 7) text(blank:false, nullable: true) }}
—
1) create a new Bar with someFloat e.g. 12,1234567 ("," as delimiter)
-> correct value in db
2) go to the edit page
-> value shown is 12,123
so now we got pretty a similar behavior to the one we had on the start.
As you can obviously tell this is bad as you will loose data when you edit a dataset.
Yeah, I guess that's related to what I mentioned in the commit comment. I think the problem is that g:fieldValue hardcodes decimal format (see here). At that point in the code there's no longer any access to the property constraints so this will take a bit of a refactor to fix.
Well yes, as far as I can tell thats a problem in the ValidationTagLib#formatValue - Method ... thats where I digged into the first time when I wrote this issue.
At least part 2) of it...
–
2)
When setting the scale-constraints for a BigDecimal higher then 3 it is not reflected in the views.
It configures the scale value correctly in the DB-Scheme. Even the create-view works correct. Correct value is persisted in DB.
But after that, only the first 3 decimal places are shown. Even on the edit page everything more then the 3 decimal places are omitted.
The result is that you loose information!
–
It is more of a taglib problem then a scaffolding problem. Maybe you want to reassign the ticket to Peter Ledbrook as he implemented that method
https://github.com/grails/grails-core/commit/665ab0c7f8fb54a58d0de083a769ffe9a7ac648c
The weird thing is that the code in ValidationTagLib looks as though it should always format to 2 decimal places but that's not what I'm seeing; if I enter a number such as 1.90 it will be re-rendered in the show and edit views as 1.9.
Is there any workaround for this issue?