Search code examples
gwtmgwt

setValue in MDoubleBox fails with Grouping/Decimal separators


I am using MDoubleBox widgets in my mgwt application, but have problems initializing values using the setValue method (applies also for setText).

Any Doubles which internally are parsed into containing Grouping or Decimal separators (ie containing a decimal or greater than 999) fails when provided as parameter giving an empty value. The corresponding gwt DoubleBox works ok. I am currently running this on a non-default Locale, but the same result occurs for the US locale, as well.

I could use MTextBox as a workaround, if there was a way to force the Numeric keyboard appearing for users entering input for these fields. Is there?

Anything I have missed regarding the MDoubleBox usage?

.ui.xml:

    <mgwt:input.MDoubleBox ui:field="field1"/>
    <gwt:DoubleBox ui:field="field2"/>

code:

    @UiField MDoubleBox field1;
    @UiField DoubleBox field2;

    field1.setValue(1234.56);
    field2.setValue(1234.56);

Output:

<blank>
1,234.56

Solution

  • It's because DoubleBox are actually <input type="text"> so "1,234.56" is fine. But MDoubleBox are <input type="number"> and they are much more restrictive and doesn't allow the , character producted by NumberFormat.getDecimalFormat().format(object) in DoubleRenderer.

    Decimals are accepted and you can configure them.

    To solve this issue you will have to dig inside MDoubleBox and use an other SDoubleBox to avoid using DoubleRenderer.

    Edit: I sent a pull request for MGWT, you can look at it to help you fix this.