how to set value programatically in an edit popup template

2 posts, 0 answers
  1. Pierre
    Pierre avatar
    260 posts
    Member since:
    Apr 2007

    Posted 05 Oct 2018 Link to this post

    Hi, in a grid popup edit template I got a field bound like:

    @Html.HiddenFor(model => model.LogoUrl)

    This field represents an image URL stored in Azure Blob.

    I already got a Kendo Upload in the edit template that upload the image to Azure, but in the KendoUpload success return function, I need to set the URL received by azure in the object currently edited. For now I try this:

    function logoUp_onComplete(e) {
        var imgURL = e.response.url;
     
        var img = $("#LogoImage")[0];
        var data = $("#LogoUrl")[0];
     
        if (img != null) {
            $(img).attr("src", imgURL);
            $(data).val(imgURL);
        }
         
    }

     

    But the databinding are not hit and the underlying model is not changed. How I can achieve that?

  2. Georgi
    Admin
    Georgi avatar
    579 posts

    Posted 09 Oct 2018 Link to this post

    Hello Pierre,

    A possible solution is to get a reference to the currently edited dataItem and modify its LogoUrl field using the set method.

    e.g.

    function logoUp_onComplete(e) {
        var imgURL = e.response.url;
        var grid = $('#grid').data('kendoGrid')
        var img = $("#LogoImage")[0];
        var data = $("#LogoUrl")[0];
      
        if (img != null) {
            $(img).attr("src", imgURL);
            grid.editable.options.model.set('LogoUrl', imgURL);
        }
          
    }

    Have in mind that the above approach will work only if the logUp_onComplete handler is executed when the popup editor is still opened. If it is not you will have to get a reference to the corresponding row and access the model via the dataItem method.


    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.
Back to Top