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

Kendo UI MVC grid popup mode insert mode model.set not working for DropDownList

3 Answers 239 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adem
Top achievements
Rank 1
Adem asked on 01 Apr 2016, 08:30 PM

I have written my issue. Please help

llink

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 05 Apr 2016, 10:45 AM

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");
      }
  }
}

Regards,
Rosen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Adem
Top achievements
Rank 1
answered on 05 Apr 2016, 01:58 PM

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");
     }
}

 

0
Rosen
Telerik team
answered on 06 Apr 2016, 10:18 AM

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");
   });

Regards,
Rosen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Adem
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Adem
Top achievements
Rank 1
Share this question
or