3 Answers, 1 is accepted
Hello Adem,
In order to set the model fields inside the edit event you will need to set it via the appropriate input element/widget and trigger the its change event in order to notify the change tracking. This is required due to the fact that there is attached a UI validation, thus only setting the model field without updating the UI will result in a validation error as the input will be still empty. For example:
function edit(e) { if (e.model.isNew() && model) { e.container.find("[name=ProductName]").val(model.ProductName).trigger("change"); var numericTextbox = e.container.find("[name=UnitPrice]").data("kendoNumericTextBox"); if (numericTextbox) { numericTextbox.value(model.UnitPrice); numericTextbox.trigger("change"); } }}Rosen
Telerik
i have tried. UI items was set. But I have gotten validation error "Customer Id is required" and grid value have not set.
function onGridEdit(e) { if (e.model.isNew() && myModel) { var d1 = $(e.container).find('input[name="CustomerId"]').data("kendoDropDownList"); d1.value(myModel.CustomerId); d1.trigger("change"); var d2 = $(e.container).find('input[name="VendorId"]').data("kendoDropDownList"); d2.value(myModel.VendorId); d2.trigger("change"); var d3 = $(e.container).find('input[name="ProductId"]').data("kendoDropDownList"); d3.value(myModel.ProductId); d3.trigger("change"); }}
Hello Adem,
I suspect that the validation message is shown as the DropDownList is not finished loading its data when the change event is triggered manually. To overcome this you may try using the dataBound event to change the value. Similar to the following: (Note the use of one, to attached the event only once)
var d1 = $(e.container).find('input[name="CustomerId"]') .data("kendoDropDownList") .one("dataBound", function () { d1.value(myModel.CustomerId); d1.trigger("change"); });Rosen
Telerik