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

how to set value programatically in an edit popup template

1 Answer 452 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 2
Iron
Iron
Pierre asked on 05 Oct 2018, 04:20 PM

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?

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 09 Oct 2018, 07:58 AM
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.
Tags
Grid
Asked by
Pierre
Top achievements
Rank 2
Iron
Iron
Answers by
Georgi
Telerik team
Share this question
or