[MGNLUI-3965] Text fields with number types don't honor user's locale Created: 28/Jul/16  Updated: 15/Mar/21  Resolved: 15/Mar/21

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

Type: Bug Priority: Neutral
Reporter: Mikaël Geljić Assignee: Unassigned
Resolution: Outdated Votes: 0
Labels: forms, localization, numbers
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
relates to MGNLUI-3508 Streamline form field attributes hand... 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

 Description   

This was revealed by running UI tests on a local+VM setup (french), more precisely SimpleFieldUITest#setTextFieldValue.

  1. Given double value is 10.22
  2. UI test (running on french machine) tries to fill input with "10,22" (commas stand for decimal in french format)
  3. Value change immediately parses that "1,022" (commas stand for thousands in english format, here it simply doesn't expect the comma here)

First half of the problem is that UI tests try to get a locale-formatted number from where the test is executed (not where the driver is running, or even better from the user's preferred locale); but second half of the problem is that TextFields (and actually all fields in general) don't get their locale set properly.

Something like this code block (± getting that locale from user prefs) should do the trick in TextFieldFactory:

Page currentPage = Page.getCurrent();
if (Number.class.isAssignableFrom(getFieldType()) && currentPage != null) {
    Locale currentLocale = currentPage.getWebBrowser().getLocale();
    if (currentLocale != null) {
        field.setLocale(currentLocale);
    }
}

... if only the AbstractFieldFactory was not resetting every field's locale with the locale of the content being edited. There is at least some confusion there.


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