Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    CellEditValueParser is removing commas from float values

    SmartClient Version: v11.0p_2016-11-22/Pro Deployment (built 2016-11-22)
    Hi, I have a number of listgrids with fields of type "float".
    On these fields I have a CellEditValueParser which takes care of parsing the value with comma as the decimal seperator incase the user has chosen this format in their settings.
    This used to work fine, but has stopped working.

    After checking the "value" argument that the parser recieves I can see that any commas are removed before the parser recieves the value. So if I enter 10,5 into the listgrid field, the parser recieves 105.
    This ofcourse makes it impossible for me to parse the value correctly.

    Do I need to change to a different type? What can I do?

    #2
    This isn't the behavior we're observing.

    First, consider using "localeFloat" as it automatically takes case of both parsing and formatting in the configured locale.

    If you want to continue using your own approach instead and you think there might be a framework issue here, please show a minimal, ready-to-run test case reproducing the issue.

    Comment


      #3
      I had considered localeFloat but as far as I could tell it just registered the locale automatically, and I would like it to be user specified.

      Here is a small test case that illustrates the problem. try to write fx. "2,5" in the field and it is sent to the parser as "25".
      Code:
      ListGridField testField = new ListGridField("test");
      testField.setType(ListGridFieldType.FLOAT);
      testField.setEditValueParser(new CellEditValueParser() {
          
          @Override
          public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) {
              SC.logWarn("Parsing: " + value);
              if(value == null)
                  return 0;
              
              String valueString = value.toString();
              valueString = valueString.replace(',', '.');
              SC.logWarn("Returning: " + valueString);
              return valueString;
          }
      });
      
      ListGrid grid = new ListGrid();
      grid.setCanEdit(true);
      grid.setFields(testField);
      ListGridRecord data = new ListGridRecord();
      data.setAttribute("test", 1.5f);
      grid.setData(data);
      HLayout mainLayout = new HLayout();
      mainLayout.setMembers(grid);
      
      return mainLayout;
      Click image for larger version

Name:	parserIssue.gif
Views:	55
Size:	37.3 KB
ID:	241716

      this is what is logged by the SC.logWarn commands: (Not sure why is runs the parser 3 times)
      Code:
      10:54:26.327:MDN3:WARN:Log:Parsing: 25
      10:54:26.327:MDN3:WARN:Log:Returning: 25
      10:54:26.328:MDN3:WARN:Log:Parsing: 25
      10:54:26.328:MDN3:WARN:Log:Returning: 25
      10:54:26.328:MDN3:WARN:Log:Parsing: 25
      10:54:26.329:MDN3:WARN:Log:Returning: 25

      Comment


        #4
        Since the field is a float, the FloatItem itself (a specialized TextItem) is calling parseFloat() as part of its own validation - the result of that is passed to ListGrid-level parsers.

        We may consider a change here in a future version, but it's a pretty strange edge-case (basically output a float, but otherwise treat it as a TextItem).

        In the meantime, you can do what you want by applying your parser to a FloatItem and applying that via field.setEditorProperties().

        Note, though, that you should still investigate using localeFloat, since you can provide a picker that allows a user to change locales at runtime, by applying the locale as a URL parameter.
        Last edited by Isomorphic; 8 Dec 2016, 06:52.

        Comment

        Working...
        X