Announcement

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

    BUG: ListGridField.defaultDynamicValue does not work unless editor receives focus

    Hi,

    When using defaultDynamicValue to set value for a field when adding new record, the dynamic value is not used unless you focus this field.
    It's even more problematic if this field is hidden.

    Tested using showcase.

    Here is a code that shows this behaviour:

    Code:
    isc.ListGrid.create({
        ID: "countryList",
        width:500, height:224, alternateRecordStyles:true,
        // use server-side dataSource so edits are retained across page transitions
        dataSource: countryDS,
        // display a subset of fields from the datasource
        fields:[
            {name:"countryName"},
            {name:"continent"},
            {name:"member_g8"},
            {
              name:"population",
              required: true,
              defaultDynamicValue: function(item, form, values) {
                return 1234;
              }
            },
            {name:"independence"}
        ],
        autoFetchData: true,
        canEdit: true,
        editEvent: "click",
        listEndEditAction: "next"
    })
    
    isc.IButton.create({
        top:250,
        title:"Edit New",
        click:"countryList.startEditingNew()"
    });
    To replicate:
    1. click Edit New button
    2. new editable row appears and cursor is in column countryName - observe editor's value in population column
    3. press Enter to end editing
    4. observe validiation error in both columns countryName and population

    vs.

    1. click Edit New button
    2. new editable row appears and cursor is in column countryName - observe editor's value in population column
    3. press tab few time or click on population editor
    4. press Enter to end editing
    5. observe validiation error only in column countryName

    Please fix this also if the population field would be hidden. It is useful to provide foreign keys for example order number when adding lines to grid showing ordered products.

    Best regards,
    Janusz

    #2
    Hi Janusz
    We have a developer looking at this issue and will follow up separately with more information when we have it.

    In the meantime a quick and straightforward solution would be to add the desired field values into the intial editValues object passed into startEditingNew()
    Code:
    click : function () {
      countryList.startEditingNew({population:1234});
    }
    Regards
    Isomorphic Software

    Comment


      #3
      Hello Janusz,
      We'd like to follow up on this one.

      We agree that the defaultDynamicValue should be respected - and it's definitely a bug that it works if you put focus in the field, but not if you don't.
      We've made a change to the framework to address this problem. This change will be present in the next nightly build, dated Jan 11 or above, branches 12.1p, 13.0p and 13.1d.

      However there is a necessary limitation to listGridField.defaultDynamicValue that means we would still recommend that you use the pattern of specifying the default values directly in the parameter passed to startEditingNew().

      When you edit a ListGrid cell, the framework creates a DynamicForm with FormItems for the fields being edited. The defaultDynamicValue function for a ListGridField is passed to the item for the relevant field, and processed there. This is evident from the method signature - the FormItem and DynamicForm are both directly passed to the defaultDynamicValue function as arguments.
      In order to be as efficient as possible, when editing ListGrids, form items are not generated for every field. They won't be generated for hidden fields, or for any undrawn fields due to incremental rendering of columns.
      This is important for scalability when dealing with very large grids.

      This means that the defaultDynamicValue will not be evaluated for undrawn fields and can't be used to apply default edit values to your grid for hidden fields (or those that may not be rendered if incremental column rendering is active).

      We'd instead recommend specifying default values in the initial edit values passed to startEditingNew(). This could be done in application code, or via a custom method on your grid which set up the appropriate defaults and then fell through to this.startEditingNew(defaults);

      We'll be updating the documentation to make this clearer

      Regards, and thank you for the clear test case

      Isomorphic Software

      Comment

      Working...
      X