Announcement

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

    FieldType.LOCALEFLOAT is not working as expected

    Hello,

    I have some problems when using FieldType.LOCALEFLOAT on FloatItem.
    Float value is shown correctly in the UI but the validation fails.
    This is my piece of code that is not working:

    @Override
    public void onModuleLoad() {


    DynamicForm form = new DynamicForm();
    form.setWidth100();
    form.setHeight100();


    FloatItem floatItem = new FloatItem("float", "Float Item");
    floatItem.setValidateOnExit(true);
    floatItem.setType(FieldType.LOCALEFLOAT.getValue());
    floatItem.setValue(456.70);

    DateItem dateItem = new DateItem("date", "Date Item");
    dateItem.setUseTextField(true);
    DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-mm-dd");
    dateItem.setValue(dtf.parse("2034-12-25"));
    dateItem.setValidateOnExit(true);

    form.setItems(floatItem, dateItem);
    form.draw();
    }

    Validation on date works fine in this case but validation on float fails every time, both if I use "," or "." .
    I need to use float in locale format.
    I use smartGWT 5.0 and I also tried 5.1 nightly build 24 March 2016.
    Can you give me a solution to this problem?
    Best regards.
    Last edited by mariusc; 24 Mar 2016, 07:32.

    #2
    You need to be setting the GWT locale for internationalization to work - see the Internationalization overview.

    Comment


      #3
      Hello,
      I set the GWT locale correctly, when I use locale=de I can see the float value as "456,70" which is fine because in german "," is the decimal separator.
      When I set locale=en I can see the float value as "456.70" which is also fine.
      But my problem arise when I want to change this value. In german I change the value to "123,45" and this new value rise a validation error. I get an error message as tooltip "Muss eine Dezimalzahl sein" (validator_notADecimal=Muss eine Dezimalzahl sein. from smartgwt messages properties file)
      In english I change value to "123.45" and also this new value rise also a validation error. I get also a tooltip "Must be a valid decimal" (validator_notADecimal=Must be a valid decimal from smartgwt messages properties file)
      So I think I set correctly the locale and internationalization works fine in my application, but FieldType.LOCALEFLOAT is not working as expected.
      When I'm using FieldType.FLOAT everything works fine, also validation is work as expected but the decimal separator is not according to locale.
      Could be that I have to set something else on my FloatItem object?

      Comment


        #4
        You seem to be saying that no matter what decimal separator you use, it's rejected in both locales? That doesn't make sense and doesn't agree with what we're seeing.

        When you say you "change the value", what specifically do you mean? If you are programmatically setting the value of the FormItem, you should be passing a Number, not a String. Any String you pass would be rejected, because the value of the field should be a Number. The locale-sensitive parsing is applied only to user input - characters actually typed into the field.

        Comment


          #5
          When I say I "change the value" this means that I change the value from keyboard for example adding a new digit at the end of old value (in my case add digit 1 at the end of old numerical value).
          So I attached 2 files for every language that I used (german and english). In the first one you can see that results are shown using locale, numerical value and date are in the correct format. After I added 1 digit at the end of numerical value from keyboard (type a new digit NOT programmatically) and I lost focus I received the validation error that I mentioned. In attachment de1.png you can see that the values look fine on UI. In attachment de2.png you can see what happens after I added 1 digit from keyboard and lost focus (the same for locale=en).
          Did I miss something to set on FloatItem object?
          Thanks a lot for your time.
          Attached Files

          Comment


            #6
            Yet the case seems to be very simple it appears to be not as simple to reproduce. Both SmartGWT 5.0 and 5.1 work as expected with the given code, validation error shows up only when really invalid decimal separator is used.
            Could you please double check if this exact code you provided results in described behavior? Also any additional details you think might be related could help. Thanks

            Comment

            Working...
            X