Announcement

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

    12.0p: Is it OK to have a ComboBoxItem with non-unique valueField?

    Hi Isomorphic,

    in this modified sample (v12.0p_2020-02-04), are there any problems / usage errors other than the fact that setting values does not work?
    Here, the DataSource has a PK (required I think), but the valueField used is not unique.

    Code:
    isc.DynamicForm.create({
        ID: "dynamicForm",
        width: 500,
        fields: [{
            name: "itemCategory",
            title: "Supply item",
            fetchDisplayedFieldsOnly: true,
            sortField: ["category", "itemID"],
            valueField: "category", [B]// This value is not unique[/B]
            displayField: "itemName",
            editorType: "ComboBoxItem",
            optionDataSource: "supplyItem",
            pickListWidth: 650,
            pickListFields: [{
                name: "itemID"
            }, {
                name: "itemName"
            }, {
                name: "category"
            }]
        }]
    });
    
    isc.IButton.create({
        ID: "buttonGet",
        width: 200,
        title: "Get DF values",
        click: "isc.say(dynamicForm.getValues())"
    });
    
    isc.IButton.create({
        ID: "buttonSetID",
        width: 200,
        title: "Set CBI value to 2500",
        click: "dynamicForm.setValue('itemCategory', 2500)" [B]// Does not work, uses category instead of ID[/B]
    });
    
    isc.IButton.create({
        ID: "buttonSetCategory",
        width: 200,
        title: "Set CBI value to 'Office Filing and Storage'",
        click: "dynamicForm.setValue('itemCategory', 'Office Filing and Storage')" [B]// Does not or better can't work, uses 1st category entry[/B]
    });
    
    isc.VLayout.create({
        membersMargin: 10,
        members: [dynamicForm, buttonGet, buttonSetID, buttonSetCategory]
    });
    Thank you & Best regards
    Blama

    #2
    valueField must map uniquely to each displayField value or behavior is, by necessity, undefined.

    Comment


      #3
      Hi Isomorphic,

      thanks for the fast answer. What is the best practice solution for the use case "Store the category of a supplyItem selected by the user"?

      I could think of EditorValueFormatter / formatEditorValue to display category while using itemID as valueField. This would display category and store itemID, which does not exactly solve the case.

      In the sample from #1, is there some negative consequence of the undefined behavior? Because right now it seems to be working for me and I don't see a problem.

      Best regards
      Blama

      Comment


        #4
        Undefined behavior means the framework can do anything, including just crash, because the usage is invalid.

        The valueField here needs to be unique. If there is a non-unique value in the record you also want to store, it’s accessible via getSelectedRecord(), then you could call setValue() on some other field, including perhaps a hidden one.

        The comboBoxItem, in the meantime, could be a form-specific item that doesn’t store anything to the DataSource.

        Comment


          #5
          Hi Isomorphic,

          thanks, that is also what we noticed now and what was why we most likely introduced a hidden artificial unique field here before.

          Perhaps you can add this information about the valueField having to be unique to the FormItem.valueField docs.
          Even if one could assume this, having it written out will reduce change for misconfiguration and misuse.

          Best regards
          Blama

          Comment

          Working...
          X