Announcement

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

    Problem with addChanged handler on ComboBoxItem?

    This problem has been observed in the 2.4 SmartGWT release using Firefox:

    We have multiple ComboBox items in our app, and just recently added a call to them in order to prevent invalid values from being saved, specifically

    setAddUnknownValues(false);

    What we observed as an unexpected side-effect is that including this prevents the onChanged handler for these items from being triggered. If the setAddUnknownValues is commented out, it works like a charm again. If commented back in, the unknown values behavior is correct, but the onChanged code is never executed.

    Can you advise ASAP?

    #2
    This property cannot be used unless you disable data paging on the ComboBoxItem, since the ComboBox needs all data in order to determine whether a given value is new. For this reason we recommend a server-side validator instead (such as hasRelatedRecord).

    Comment


      #3
      Hi,

      I too am seeing the problem where the onChanged event does not fire if the setAddUnknownValues=false option is used.

      As suggested, I disabled paging on the form by setting: form.setDataFetchMode(Local)

      however, the onChanged event still does not fire.

      Must I do something else to truly disable the paging such that the onChanged event fires?

      Thanks in advance!
      ~Jeremy

      Comment


        #4
        That call would not disable paging. filterLocally will.

        Comment


          #5
          Isomorphic,

          Thanks for the quick reply! Unfortunately, using filterLocally=true did not resolve the problem either. I as still seeing that the onChanged event is not firing when using the addUnknownValues=false option.

          I'm using the released SmartGWT 2.4 code, and here is a code snippet that demonstrated the problem:
          Code:
          // Define Form and ComboBoxItem
          DynamicForm form = new DynamicForm();
          
          ComboBoxItem comboBoxItem = new ComboBoxItem("MyComboItem");
          comboBoxItem.setAddUnknownValues(false);        
          comboBoxItem.setDisplayField("valueField");
          comboBoxItem.setValueField("keyField");
                  
          // onChange Handler
          comboBoxItem.addChangedHandler(new ChangedHandler()
               {			
                    @Override
                    public void onChanged(ChangedEvent event)
                    {
                         SC.say("Value Changed to:" + event.getItem().getValue());
                    }
               });
                  
          // Set the filterlocally (in the hopes of disabling paging)
          // and get the onChange event to fire properly
          comboBoxItem.setFilterLocally(true);
                  
          // Define DataSource
          DataSource optionDS = new DataSource();
          optionDS.setClientOnly(true);
                  
          DataSourceTextField keyField = new DataSourceTextField("keyField");
          keyField.setPrimaryKey(true);
          DataSourceTextField valueField = new DataSourceTextField("valueField");
          optionDS.setFields(keyField, valueField);
          comboBoxItem.setOptionDataSource(optionDS);
                  
          // Add 2 records to the DS
          Record rec1 = new Record();
          rec1.setAttribute("keyField", "1");
          rec1.setAttribute("valueField", "Value1");
          optionDS.addData(rec1);
                  
          Record rec2 = new Record();
          rec2.setAttribute("keyField", "2");
          rec2.setAttribute("valueField", "Value2");
          optionDS.addData(rec2);
                  
          comboBoxItem.setOptionDataSource(optionDS);
          form.setFields(comboBoxItem);

          Comment


            #6
            Can you try this on a nightly build of 2.5? It should already be corrected, please confirm.

            Comment

            Working...
            X