Announcement

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

    Two ComboBoxItems using the Same Option DataSource - how to set display Value in one when other changes

    SmartClient Version: v11.1p_2017-08-08/PowerEdition Deployment (built 2017-08-08)

    I have two ComboBoxItems in the DynamicForm, which are derived from the same datasource. The SQL table is a tree of a two levels, with 3 columns: a pk, branch, leaf. One ComboBox, displays the value of the branch, the other Combo box displays the value of the leaf column.

    When the form first draws there is no problem, each ComboBox shows the correct display value for a given pk.

    However I want to allow the user to use either the branch ComboBox or leaf ComboBox to change their selections. Let's take the example of the user changing the Leaf ComboBox. The user gets the appropriate drop down list and makes a change to Leaf. However this should or could now change the branch display to some other display value.

    I have attempted to use,
    a) addChangedHandler on the Leaf ComboBox, and
    b) on the branch ComboBox setPickListFilterCriteriaFunction( new com.smartgwt.client.widgets.form.fields.FormItemCriteriaFunction () { } ); to alter the criteria of the branch ComboBox criteria, and
    c) Branch.setValue(Leaf.getValue())
    d) Branch.setCachePickListResults(false);

    to attempt the Branch Display value to update, but it does not. It does do a fetch, but there is no update of the DisplayValue. The Branch ComboBox sets the display with the Value field, i.e. the pk value.

    Basically I am trying to set the Branch ComboBox displayValue, but there is no obvious way that I can find to do this. Any suggestions? Is it possible to cause the Branch ComboBox to update it's display value?


    #2
    You can't set the displayValue of the ComboBox directly, because that would put it in an invalid state where it doesn't know the value for the valueField, but the value should not be reported as null.

    Once a value has been chosen in the other ComboBox, you can use getSelectedRecord() to discover a proper valueField value, and give that to the other comboBox via setValue().

    In situations where getSelectedRecord() is null (eg immediately after a programmatic change to the valueField), you can just do a fetch against the DataSource to retrieve the value for the valueField.

    Comment


      #3
      Thanks for the reply. Makes sense.

      I am now using getSelectedRecord to find the proper valueField value in the Leaf ComboBox. But I need to translate that value to the appropriate value of Branch Combo box, which is a sorted list and therefore does not contain all the same key/values of the Leaf ComboBox.

      I have attempted to Map branchMap = BranchComboBox.getValueMap(); to do the translation but it always returns a null. I can't get that ComboBox's value map. Fetching all the unsorted values of the BranchComboBox through the dataSource doesn't really tell me the key/value pairs of the actual ValueMap of the BranchComboBox, unless I make some assumptions about how the widget has created it's internal ValueMap.

      Why is BranchComboBox.getValueMap(); always null?

      Comment


        #4
        From your limited description, you have not called setValueMap(), so you should expect getValueMap() to be null.

        Perhaps you are thinking of the part of the docs that mention that the optionDataSource is used in lieu of a valueMap? While this is a useful way to think of the optionDataSource, we don't literally populate the valueMap property from the optionDataSource, as that would only work for small datasets that can be fetched completely. However, if your dataset is small enough, you can derive a valueMap yourself, and use it in the way you had in mind.

        Comment


          #5
          Again, thanks.

          I did eventually derive the value map myself, using the ComboBox's DataSource, DSRequest and default Criteria. Once I did that I knew the mapping between it's value set and display set, in short the ComboBox's ValueMap of the Branch. Knowing the Leaf value, I was able then to interpolate and set the correct value for the Branch ComboBox.

          Hopefully this conversation may be of use to others.

          Comment

          Working...
          X