Announcement

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

    Blanking out dependent select values

    Good morning,

    I have a ListGrid with dependent values. To avoid user confusion, when the primary value changes I'd like to clear the dependent value. Additionally, the dependent column is required.

    When I use the code below, or similar code with an explicit custom validator, two odd things happen (which I believe are related).

    1) The required property on the dependent field is not checked (and custom validators do not fire).
    2) The dependent value reverts back to its prior value (which is likely not appropriate for the current primary value).

    Steps to reproduce:

    Start with the dependent select example: http://www.smartclient.com/docs/6.5.1/a/system/reference/SmartClient_Explorer.html#_Grids_Editing_Databound.Dependent.Selects

    Edit the code to look like this (aside from formatting, the only material change s are the "changed" handler on the primary value, and the "required" flag on the dependent value):

    Code:
    isc.ListGrid.create({
        width: 500,
        height: 200,
        canEdit: true,
        ID: "orderList",
        
        fields: [
            {name: "quantity", 
                title: "Qty", 
                type: "integer", 
                width: 30
            },
            {name: "categoryName", 
                title: "Category", 
                editorType: "select", 
                optionDataSource: "supplyCategory", 
                autoFetchDisplayMap: false, 
    
                changed: function(form, item, value){
                    form.getField("itemName").clearValue();
                }
            },
            {name: "itemName", 
                title: "Item", 
                editorType: "select", 
                required: true,
                optionDataSource: "supplyItem", 
                autoFetchDisplayMap: false,
                editorProperties: {
                    getPickListFilterCriteria: function(){
                        var category = this.grid.getEditedCell(this.rowNum, "categoryName");
                        return {category: category};
                    }
                }
            }    
        ]
    });
    
    isc.IButton.create({
        top: 225,
        title: "Order New Item",
        click: "orderList.startEditingNew({quantity:1})"
    })
    Add a new row and select a primary value and a dependent value, then save.

    Edit that row and select a new primary value, do not select a dependent value, then save.

    At this point the old dependent value will be in the grid with the new primary value, showing an invalid combination.

    I would have expected at that point that the field would remain blank, and required validator would fire and not save the record. My theory is that since we're changing the dependent value programatically, SC is getting confused and not throwing some "dirty" flag somewhere and the validators are not being run.

    Possibly unrelated but if you add allowEmptyValue: true and manually select the blank value the validators fire. That's what led me to believe that the issue is the "dirty" flag.

    Is this the recommended way to clear a ListGrid editValue?

    Thanks in advance. Let me know if you need anything more from me.
    Rob

    #2
    Instead of clearValue(), try instead item.grid.setEditValue("itemName", "");

    Comment


      #3
      Sorry that should be item.grid.clearEditValue(item.grid.getEditRow(), "itemName");

      Comment


        #4
        clearEditValues() seems to work when you change the values around before saving (add operation), but does not seem to work once the record is saved then edited again (update operation).

        Rob
        Last edited by RHelgeson; 16 Apr 2009, 10:15.

        Comment


          #5
          Yes, because editValues are unsaved values. When the record is successfully saved, there are no editValues.

          If what you want to do is clear out the value in a way that essentially simulates the user having cleared it, you can setEditValue(item.grid.getEditRow(), "itemName", "").

          Comment

          Working...
          X