Problems with Default value

I have set a default value for a text item in a dynamic form.(in the datasource itself).
Issue 1
If have marked this field as required = true in the datasource
During add or modification if i havn’t touched the text item and call the saveData() method it is giving an validation like ‘Field is required’ . It doesn’t consider the default value there.

Issue 2
During add or update if haven’t edited the defaut value of the field( I haven’t touched field) then in teh server it is giving null value and not giving the default value for the field.

Can you please help me…

Hi Rahadurai
This should work fine - it’s actually easy to test by modifying this example - removing the ‘values’ property from the DynamicForm.create(…) block, and adding a defaultValue=“Bob” to the firstName field in the DataSource. The defaultValue shows up, and validation proceeds successfully for that field without further modification.

When this fails for you, are you seeing the default value showing up in the text field at all? Are you getting any JS errors or other unexpected warnings logged in the developerConsole?
If there’s nothing obvious, perhaps you could post the code for your DataSource definition, and DynamicForm definition so we can take a look?

Thanks
Isomorphic Software

Not working in a list grid

Hi,
Thaniks,for the reply. That is working fine in a Dymanic Form.
But I have created a List grid with the same datasource.

      But this is not working in the list grid..

[ I will explain the scenerio again
I have a field in a list grid with some ‘defaultValue’ and this is a ‘required’ feild.

  1. When i add a new record and without giving any new values ( i am retaining the default value) for the field.
    During validation it says ‘Field is required’…
    Can you help me to resolve this..

Hi rajadurai
Try setting editorProperties:{defaultValue:[default field value]} on your field. This will ensure the defaultValue is passed to the edit form item when the record is edited in the grid.
You can see the documentation for ListGridField.editorProperties here. Note that you can set editorProperties on the field definition in the grid, or at the DataSource level.

Another option would be to pass in a default set of values for the record as parameters to the startEditingNew() call.

Let us know if you still can’t get this working
Thanks
Isomorphic Software

Working.. But still i need more

Hi,
One think i need to clear that i don’t find any problem with setting the default values for a listgrid field. Using defaultValue or editorProperties i can able to set and it is getting displayed in the field.

    But the problem here is if i don't move the control to the field ( which has a default value there) and tried to save the row after giving values to other fields in the row... Its giving the validation error message 'Field is required'( seems like it doesn't consider the default value). This problem persist even after i used 'editProperties'

In your expolorer page – > Go to the ListGird –> Edit new rows-example.. I have attached the code here

isc.ListGrid.create({
    ID: "countryList",
    width:500, height:224, alternateRecordStyles:true, showAllRecords:true, cellHeight:22,
    // use server-side dataSource so edits are retained across page transitions
    dataSource: countryDS,
    // display a subset of fields from the datasource
    fields:[       
        {name:"member_g8"},
        {name:"continent",editorProperties:{defaultValue:["Asia"]},required:true},
        {name:"countryName",editorProperties:{defaultValue:["India"]},equired:true},
        {name:"population", 
         formatCellValue:"isc.Format.toUSString(parseInt(value))"},
        {name:"independence"}
    ],
    autoFetchData: true,
    canEdit: true,
    editEvent: "click",
    listEndEditAction: "next"
})
//
isc.IButton.create({
    top:250,
    title:"Edit New",
    click:"countryList.startEditingNew()"
});

the above code is not giving me the expected result…

But the second option what you gave me ( sendig default value set to startEditingNew())
is woking filne…

isc.IButton.create({
    top:250,
    title:"Edit New",
    click:"countryList.startEditingNew({continent:'Asia',countryName:'India'})"
});

Ok… My problem is being solved here.. Thanks.

 But i would be fine if i get it through the editorProperties.. Since in my appication i made the code more generic. I need 50+ list grids like this.. So that i used the datasource

xml to define all the properteis of a screen. If i am able to this default values for the fields in the datasource xml it will be fine..

Iwill this simpel way ( defining default values in the Datasouce itself) work in future..?

I will be happy with that…
Thanks for this current solution to make it working

similar problem like this

Hi,
In my listgrid i am setting value for a field (which is a required field) during the ‘Change’ event of a paricular ComboBox.
In this case after setting the value for the required feild through code , if i tried to save.
than the validation error message(Field is required) is coming.
If i move the control over the field then there is no problem..

The problem here is
It is not accepting the field values ( eventhough the value is displayed on the field ) which are set through coding.. if you didn’t touch the field.

 But if you set the values for a field through code( in the change event of other field)and then move the control over the field then it is accepting value...

Can you solve my proplem in your example…
I need the following in this example..

If you select the continent as ‘Asia’ then the countryname should be set to ‘India’.
then without mioving the control to country field if i save it should not give me the validation error..

isc.ListGrid.create({
    ID: "countryList",
    width:500, height:224, alternateRecordStyles:true, showAllRecords:true, cellHeight:22,
    // use server-side dataSource so edits are retained across page transitions
    dataSource: countryDS,
    // display a subset of fields from the datasource
    fields:[
        {name:"countryName",required:true},
        {name:"continent"},
        {name:"member_g8"},
        {name:"population", 
         formatCellValue:"isc.Format.toUSString(parseInt(value))"},
        {name:"independence"}
    ],
    autoFetchData: true,
    canEdit: true,
    editEvent: "click",
    listEndEditAction: "next"
})

isc.IButton.create({
    top:250,
    title:"Edit New",
    click:"countryList.startEditingNew()"
});

Can you help me in this..

Thanks in advance..

Hello,

In this case you would set a change handler in the editorProperties for the field. This change handler would then call ListGrid.setEditValue() for the row that’s currently being edited.

For this example, in the ListGrid definition:

...
fields:[
    {name:"continent", editorProperties:{change:"countryList.updateName(value)"}},
    ...
],
updateName : function (value) {
    if (value == 'Asia') {
        this.setEditValue(this.getEditRow(), 'countryName', 'India');
    }
},
...