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

4 posts, 0 answers
  1. Adem
    Adem avatar
    13 posts
    Member since:
    Feb 2016

    Posted 01 Apr Link to this post

    I have written my issue. Please help

    llink

  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 05 Apr Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Adem
    Adem avatar
    13 posts
    Member since:
    Feb 2016

    Posted 05 Apr in reply to Rosen Link to this post

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

     

  5. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 06 Apr Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready