Announcement

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

    DynamicForm fields with null values are sometimes cleared when form redraws

    Isomorphic ,

    I noticed an issue with the DynamicForm clearing fields that have a null value if the form is redrawn due to an item changing. It only occurs when a scrollbar is introduced by the redraw. This results in the field not being included when saving the form data.

    The following sample code reproduces the issue. You need to clear the text for Item 1 first and then change Item 2. You'll notice that when you choose "Scrollbar", Item 1 is cleared (i.e. reset to the default value).

    Code:
     public void onModuleLoad() {
            DynamicForm form = new DynamicForm();
            form.setNumCols(1);
            form.setTitleOrientation(TitleOrientation.TOP);
    
            TextItem item1 = new TextItem("item1", "Item 1");
            item1.setDefaultValue("Clear this item first");
    
            SelectItem item2 = new SelectItem("item2", "Item 2");
            item2.setValueMap("Then change this", "No Scrollbar", "Scrollbar");
            item2.setDefaultToFirstOption(Boolean.TRUE);
            item2.setRedrawOnChange(Boolean.TRUE);
    
            TextItem otherItem1 = new TextItem("otherItem1", "Other Item 1");
            otherItem1.setStartRow(Boolean.TRUE);
            otherItem1.setShowIfCondition((i, v, f) -> "No Scrollbar".equals(item2.getValueAsString()));
    
            TextAreaItem otherItem2 = new TextAreaItem("otherItem2", "Other Item 2");
            otherItem2.setStartRow(Boolean.TRUE);
            otherItem2.setShowIfCondition((i, v, f) -> "Scrollbar".equals(item2.getValueAsString()));
    
            form.setItems(item1, item2, otherItem1, otherItem2);
    
            Window w = new Window();
            w.setCanDragResize(Boolean.TRUE);
            w.setHeight(200);
            w.setWidth(500);
            w.addItem(form);
            w.show();
        }
    I'm using the following:

    SmartClient Version: v12.1p_2022-01-29/Pro Deployment (built 2022-01-29)
    Stratus skin
    Chrome 99.0.4844.74 (Official Build) (64-bit)

    Thanks
    Last edited by stonebranch3; 24 Mar 2022, 06:08. Reason: Changed field title

    #2
    Hi Isomorphic,

    Just wanted to follow up to see if you had any update you could share on this issue yet?

    Thank you

    Comment


      #3
      The main update we wanted to share is wow! How did you find this, and thank you! We will need a bit of time to figure out how best to address this (we are working around some odd browser DOM issues).

      In the meantime, would you like us to figure out a workaround? Because it seeks like you already have it isolated to the extent that you are probably ahead of us on that front.

      Comment


        #4
        Hi Isomorphic,

        Yes, indeed, a workaround would be very much appreciated. Would this be something isolated with limited impact?

        stonebranch3 was able to correlate the problem based on details from end users.

        Regards

        Comment


          #5
          Hi!
          Well, we've come up with a fix.
          We've now made a change that should fix this issue in the 12.1 branch and more recent branches. It'll be in nightly builds going forward, dated March 29 and above.

          Please let us know if you continue to see this problem or any other oddities that seem related

          Thanks, and thanks again for the clear test case

          Isomorphic Software

          Comment


            #6
            Thank you!
            We will give the build a try as soon as it's available.

            Comment


              #7
              Isomorphic

              Thanks for the fix. It resolves the issue with the original use case, however, we did notice another use case that has a similar issue with the value getting cleared. In this case, the field that is cleared is hidden and then shown again.

              I have provide the test case for this below. You just need to clear the text for Item 1 first, then change Item 2 "Hide Item 1", then change Item 2 to "Show Item 1". You'll notice Item 1 has been reset to the default value.

              Code:
              public void onModuleLoad() {
                      DynamicForm form = new DynamicForm();
                      form.setNumCols(1);
                      form.setTitleOrientation(TitleOrientation.TOP);
              
                      TextItem item1 = new TextItem("item1", "Item 1");
                      item1.setDefaultValue("Clear this item first");
              
                      SelectItem item2 = new SelectItem("item2", "Item 2");
                      item2.setValueMap("Show Item 1", "Hide Item 1");
                      item2.setDefaultToFirstOption(Boolean.TRUE);
                      item2.addChangedHandler(e -> {
                          Object value = e.getValue();
                          if ("Hide Item 1".equals(value)) {
                              item1.hide();
                          } else {
                              item1.show();
                          }
                      });
              
                      form.setItems(item1, item2);
              
                      Window w = new Window();
                      w.setTitle("Show/Hide Test");
                      w.setCanDragResize(Boolean.TRUE);
                      w.setHeight(200);
                      w.setWidth(500);
                      w.addItem(form);
                      w.show();
                  }
              SmartClient Version: v12.1p_2022-03-29/Pro Deployment (built 2022-03-29).

              Thanks

              Comment


                #8
                Hi Isomorphic,
                Checking in to see if you have everything you need from our end for the new use case?
                Thanks

                Comment


                  #9
                  Hi
                  Your code to reproduce this issue is clear. We see the problem and have a developer looking at it.

                  A couple of quick workarounds which may be acceptable to you:
                  - If you're not explicitly calling 'editRecord()' or 'setValues()' on the form to edit a meaningful value-set and are just looking to set default values, you can always call item.setValue() to set its initial value.
                  - Alternatively - if you do need a default value which will show up if the value is programatically set to null/undefined, or clearValue() is called for the item, you may be able to call setEmptyStringValue("") on the item.
                  This will cause the value to be set to an empty string rather than true null when the user clears the field, but if this is acceptable for your usage it will sidestep this issue.

                  Let us know if either of these will work for you for right now.
                  In the meantime we are still looking at the underlying problem.

                  Regards
                  Isomorphic Software


                  Comment


                    #10
                    Hi Isomorphic,

                    The workaround is not an option for us, however, we appreciate the suggestion.

                    The sample, using the default value, is merely an over simplification for demonstration purposes to show the reset is happening.

                    We will proceed with using the march 30th build in the meantime.

                    Thank you

                    Comment


                      #11
                      Thank you for the update.

                      For now we have reverted our build and will continue with our investigation and provide any information we can collect to you.

                      Regards

                      Comment


                        #12
                        NOTE: Stonebranch hit a problem with File Upload in the updated version of SmartGWT Pro (12.1).

                        This discussion has been shifted to a new thread here: https://forums.smartclient.com/forum...-sgwtpro-12-1p

                        We'll continue to use this thread to discuss the original problem with values being reset to the default in forms

                        Comment


                          #13
                          We've made a change to address this issue and ported it back to 12.1. Please try the next nightly build (April 5 or above) and let us know if the problem persists, or manifests in any other ways!

                          Regards
                          Isomorphic Software

                          Comment


                            #14
                            Both issues are resolved now. Thanks!

                            Comment

                            Working...
                            X