[MGNLUI-4066] TextFieldDefinition with "Double" or "Decimal" type should not round input values Created: 03/Nov/16  Updated: 05/Oct/21  Resolved: 02/Dec/16

Status: Closed
Project: Magnolia UI
Component/s: forms
Affects Version/s: 5.4.7
Fix Version/s: 5.5.1

Type: Bug Priority: Major
Reporter: Mikaël Geljić Assignee: Oanh Thai Hoang
Resolution: Fixed Votes: 1
Labels: converter, double
Remaining Estimate: 0d
Time Spent: 3d
Original Estimate: 3d

Issue Links:
Relates
relates to MGNLUI-6896 TextFieldDefinition with "Double" or ... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:
Sprint: Saigon 73
Story Points: 5

 Description   

Vaadin applies StringToDoubleConverter by default for Double properties.
This converter internally uses a default NumberFormat instance with maximumFractionDigits set to 3.

When applying the new value back on the server-side, Vaadin's AbstractTextField does this thing of beauty:

T doubleConvertedFieldValue = convertFromModel(convertToModel(newFieldValue))

This immediately updates the presentation to however this value would be rendered at a later point. I haven't dug yet why the approximated presentation value bubbles back to the model though.
Even then, our forms are rightfully immediate, so we don't want to show a rounded value when user blurs the field (locale-dependent formatting still welcome).

Proposal

I suggest we bridge the gap and override StringToDoubleConverter#getFormat() and #setMaximumFractionDigits() to whatever more meaningful, then assign it automatically from the TextFieldFactory when property type is Double.


Original report

I use magnolia 5.4.7 and try to define a filed with type Double or Decimal in my app to save google maps coordinates in yaml:

- name: latitude
  class: info.magnolia.ui.form.field.definition.TextFieldDefinition
  type: Double

the app does work, but I only can keep 3 digital after point no matter what I enter. For example, I entere "10.123456789", after the field lost focus, it will be show as 10.123. Even it displayed as "10.123456789" after save and check the value again it saved as 10.123. How I can save all digital as double?

via Magnolia forums: TextFieldDefinition with type "Double" or "Decimal" only can keep 3 digitals after point



 Comments   
Comment by Khoa Nguyen [ 05/Oct/21 ]

Hello. I have the same thing happening in Magnolia 6.2.11

Generated at Mon Feb 12 09:12:54 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.