gpc / fields

a spiritual successor to the bean-fields plugin
http://gpc.github.io/fields/
84 stars 106 forks source link

numeric field editing broken #317

Open xpusostomos opened 2 years ago

xpusostomos commented 2 years ago

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

osscontributor commented 2 years ago

It ends up generating this HTML:

What is it that ends up generating that HTML?

chrisbitmead commented 2 years ago

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

CJD888 commented 1 year ago

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