Announcement

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

    Filtered SelectItem Displaying Wrong Value

    Given a SelectItem based on a three-column DataSource where
    1. the first column represents a code category
    2. the second a valid code for each category (and possibly duplicated across categories)
    3. a description
    the selected display value can show the description from the wrong row despite filtering on the category. For example, the below code plugged into your online showcase resulted in the display value of "Cat B Opt D" when filtered for category A, with option 'D' selected. The picklist shows the correct options (e.g., "Cat A Opt D"), but that selection ends up displaying "Cat B Opt D". Is this a bug or is there a workaround to make this work without having to have unique datasources for each category?


    Code:
    isc.DataSource.create({
        ID: "testDS",
        fields:[
            {name:"pid", primaryKey: true, hidden:true},
            {name:"category", title:"Category"},
            {name:"option", title:"Option"},
            {name:"name", title:"Name"}
        ],
        clientOnly: true,
        cacheData: [
        {pid: 1, category: "A", option: "A", name: "Cat A Opt A"},
        {pid: 2, category: "A", option: "B", name: "Cat A Opt B"},
        {pid: 3, category: "A", option: "C", name: "Cat A Opt C"},
        {pid: 4, category: "A", option: "D", name: "Cat A Opt D"},
        {pid: 5, category: "B", option: "D", name: "Cat B Opt A"},
        {pid: 6, category: "B", option: "D", name: "Cat B Opt B"},
        {pid: 7, category: "B", option: "D", name: "Cat B Opt C"},
        {pid: 8, category: "B", option: "D", name: "Cat B Opt D"}
    ]
    })
    
    isc.defineClass("OptSelect", "SelectItem").addProperties({
        optionDataSource:"testDS",
        valueField: "option",
        displayField: "name",
        pickListFields:[{name:"option", width:20},{name:"name",width:100}],
        width: 140,
        filterLocally: true,
        sortField:"option"
    });
    
    isc.DynamicForm.create({
        ID:"testForm",
        width: 500,
        fields : [
          {
            name:"option",
            editorType:"OptSelect",
            pickListCriteria: {category: "A"}
          }
        ]
    });
    Last edited by gwque; 5 Feb 2021, 09:18.

    #2
    There is no primary key in your DataSource, this is required.

    Comment


      #3
      My true case does have a primaryKey. I've added one to the sample code above, and the same issue occurs. Any other suggestion?

      Comment


        #4
        See docs: valueField must be unique. You have several duplicates.

        Comment


          #5
          Thanks, but sorry to hear that. I guess this answers my question - either a unique datasource per category or I have to make the value field concatenated even though it duplicates the category value.

          FWIW, below is a snip of the valueField description from the pickList properties page. Here, at least, I don't see anything that says it requires unique values. It might prevent these types of questions for you if it stated something to that effect: perhaps something like "values must be unique to work properly, even if filtering is applied that would make the value selection unique based on that filter".
          valueField [IR] [Advanced] type:String, defaultValue: null
          If this form item maps data values to display values by retrieving the FormItem.displayField values from an optionDataSource, this property denotes the the field to use as the underlying data value in records from the optionDataSource.
          If not explicitly supplied, the valueField name will be derived as described in FormItem.getValueFieldName().

          Getter: PickList.getValueFieldName()

          Comment


            #6
            This is not a limitation of the control, there's just no way this could work as you hoped, with any UI control.

            See the optionDataSource docs (which are the docs you read to find out about valueField and displayField): the valueField value is used to fetch the displayField. If the valueField is not unique, then when you provide values to a form including *just* a value for the valueField, there is no way to know which related record is meant.

            So this is not a limitation of the UI control, it's just not possible to know which category and option combination is meant if you only store the category value.

            In your actual data model, you must either storing the a unique ID for a combined category+option record, or you are storing both category and option together - again, no other way this can work.

            Both approaches are readily accommodated:

            1. If you are storing a unique ID of the combined category + option record, then just make that the valueField and you're done.

            2. if, in your data model, both category and option are stored, but for whatever reason you want to pick both at once, then just do that: have actual field definitions for category and option in your DataSource, hide them in this form, and when a category and option combination is picked in the dropdown, populate the two hidden fields and save.

            Comment

            Working...
            X