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

Hidden field value null on save click CustomEditorTemplate

1 Answer 659 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Anamika
Top achievements
Rank 1
Anamika asked on 23 Jul 2014, 11:54 AM
Hello,

I am using the CustomeditorTemplate sample and adding my Project specific fields. My requirement is in custoeditoetemplate ObjectID should be hidden field and another textfield for description and on a button click i choose object from a popup window and populate description and hidden field ObjectID. On save should get objectid and description both.
But with hiddenfield ObjectID is always null . So i tried ObjectID as TextBox and populate a dummy text 'hello' on button click. Interesting to see the 'hello' in the TextBox but when i click save ObjectID is null. But if i edit hello to hello1 or something just Need to edit and then click save then i get Objectid value.

Why so, populating in jquery does not make textbox dirty ?
here is the customeditortemplate code

< script>

function TestClick(e) {
$('input[name="txtObjectID"]').val('hello');
};



< /script>
< div class="k-edit-label">
@(Html.LabelFor(model => model.ObjectID))
< /div>
< div data-container-for="ObjectID" class="k-edit-field">
@(Html.TextBoxFor(model => model.ObjectID, new { @class = "k-textbox", data_bind = "value:ObjectID",Name="txtObjectID" }))
< input class="k-button" id="searchBtn" style="width:20px" type="button" value="...." onclick="TestClick(this)" />
< /div>

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 25 Jul 2014, 08:56 AM
Hello Anamika,

The Model field value is not updated as setting the value of the input element does not trigger its change event. Therefore, the MVVM binding is not notified that the input is changed. The easiest way to correct this is to manually trigger the change event of the input after its value has been changed.

function TestClick(e) {
     $('input[name="txtObjectID"]')
              .val('hello')
              .trigger("change");
};


Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Scheduler
Asked by
Anamika
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or