Hidden field value null on save click CustomEditorTemplate

2 posts, 0 answers
  1. Anamika
    Anamika avatar
    157 posts
    Member since:
    Mar 2014

    Posted 23 Jul 2014 Link to this post

    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>
  2. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 25 Jul 2014 Link to this post

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