This is a migrated thread and some comments may be shown as answers.

Set values in model when opening new popup edit window

1 Answer 613 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 1
Jose asked on 03 Sep 2018, 09:10 PM

     I'm trying to set values to the empty model when i click add and show the custom edit template, i've set them through javascript but it doesn't show on popup window.

 

function onEdit(e) {
            var today = new Date();
            e.model.FECHA = today;
            console.log(e.model)
        }

 

Also i've set them in the model constructor but it doesn't work, the only way to set it is via javascript and delaying the script a few seconds but this solution it's not reliable

 

thank you

 

 

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 05 Sep 2018, 11:08 AM
Hi Jose,

Based on the provided information I assume that the requirement is to set a default value to a field. Please correct me if I am wrong.

A possible solution is to set the default value within the configuration of the model.

e.g.
.DataSource(dataSource => dataSource
    .Ajax()
    ...
    .Model(model =>
    {
        model.Field(p => p.FECHA).DefaultValue(DateTime.Now);
    })
   ...
)

Or use the set method within the edit event handler.

e.g.

function onEdit(e) {
            var today = new Date();
            e.model.set( 'FECHA',today);
            console.log(e.model)
        }


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Jose
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or