fields icon indicating copy to clipboard operation
fields copied to clipboard

numeric field editing broken

Open xpusostomos opened this issue 4 years ago • 3 comments
trafficstars

If I have a field in my domain class:

Long myField

and that field has a value of 1000000. It ends up generating this HTML:

<input type="number" name="weighting" value="1,000,000" required="" id="myField" />

Those commas mean that the value is never seen because html numeric fields don't like commas.

Tracing the code, this comes from FormFieldsTagLib.groovy line 729:

attrs.value = numberFormatter.format(propertyAccessor.value)

As far as I can see, there should never be locale specific formatting for input fields. Display fields... maybe. But not input fields.

Furthermore, if the type of the field is float or big decimal, the input field looks like this:

<input type="number decimal" name="depreciationRate" value="" id="depreciationRate" />

as far as I know "number decimal" is completely invalid html. Furthermore, if you put a constraint on the field of say min: 0.0 it will generate this:

<input type="number decimal" name="depreciationRate" value="" min="0.0" id="depreciationRate" /> with a min="0.0" attempting to enforce the minimum. Which doesn't work because the browser falls back to "text" for the invalid "number decimal", and therefore min= is ignored by the browser.

This is all very broken, not a minor bug here! 3.0.0.RC1

xpusostomos avatar Oct 30 '21 10:10 xpusostomos

It ends up generating this HTML:

<input type="number" name="weighting" value="1,000,000" required="" id="myField" />

What is it that ends up generating that HTML?

jeffscottbrown avatar Jun 30 '22 12:06 jeffscottbrown

Sorry for the lack of clarity. This is when using the auto generated CRUD views which are presumably part of the form fields plugin.

chrisbitmead avatar Jul 05 '22 06:07 chrisbitmead

The problem is in FormFieldsTagLib.groovy renderNumericInput() which added localized number formatting. I guess It should not apply formatting when rendering an edit field somehow.

A quick fix is to disable localized numbering using config grails.plugin.fields.localizeNumbers = false

CJD888 avatar Oct 05 '22 15:10 CJD888