How to change value of Textbox in Editor Template for cell. Value provided to server differs to displayed value.

4 posts, 0 answers
  1. Malcolm
    Malcolm avatar
    29 posts
    Member since:
    Oct 2011

    Posted 01 Jul 2013 Link to this post

    Dear KendoUI Team!
    I hope you can help me out. I want to update some Editor Templates from the old Telerik Controls. I am using ASP.Net MVC 4.

    My Editor Template looks like this

    @model string
    @using System.Collections
    <div style="white-space:nowrap;">
     
     
        @Html.TextBoxFor(m => m, new { onclick = "setInvisible(\"SplitCountryList#=Rid#\")", onfocus = "setInvisible(\"SplitCountryList#=Rid#\")", id = "CoPrefSplit#=Rid#" })
        <button id="SplitCountryDisplay" onclick="setVisibleAndFocus('\\#SplitCountryList#=Rid#','\\#SplitCountryCombo-input')" style="background-color:White; width: 20px; height:22px; font-size: 6pt">...</button>
    </div>
     
    <div id="SplitCountryList#=Rid#" style="position: absolute; overflow:visible; width:250px; z-index:99; margin-top: 0px; visibility:hidden;">
    @(Html.Kendo().ComboBoxFor(m => m)
            .Name("SplitCountryCombo#=Rid#")
            .BindTo(new SelectList((IEnumerable)ViewData["Countries"], "Code", "DisplayName"))
            .HtmlAttributes(new {@ArticleID = "#=Rid#"})
            .Filter(FilterType.Contains)
            .Events(events => events
                .Change("onSplitCountryChanged")
            )
        )
    </div>

    What I want to do is to set the value of the Textbox in the Change Event of the Combo-Box. My Approach is using .val()

    $(elementName).val(e.sender.dataItem().Value);

    The value displayed in the Textbox is changed then. BUT: The value transfered to the server is the old value of the Textbox.

    Example:
    The field has the value "US".  I edit the row.  I change the value to "CN" using the Combobox. "CN" is now displayed in the textbox in edit mode. When I want to update the row, "US" is provided as the value for the field in the model.

    Is there a way to make kendoUI transfer the values that are displayed?

    brgds
    Malcolm Howlett
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 03 Jul 2013 Link to this post

    Hi Malcolm,

     
    From the provided information it's not clear for us what is the exact setup that you have  - could you please provide small example project that reproduced the issue? This would help us pinpoint the exact reason for this behavior.

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Malcolm
    Malcolm avatar
    29 posts
    Member since:
    Oct 2011

    Posted 09 Jul 2013 Link to this post

    Attached you find a simple project that shows the problem.
    Try the following:
    - Edit a row
    - Klick the button (...) in the country2 colum
    - You will now see a combobox
    - Choose a different value for country2 than 'C1' using the combox!
    - You will see the new value in the Textbox for country2
    - Set a breakpoint in the Update method of the home controller
    - Update the row.
    - You will see that the value provided to the controller for country2 is still 'C1'. But the value displayed in the Textbox ist not 'C1'.
  4. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 11 Jul 2013 Link to this post

    Hi Malcolm,

    After reviewing the provided project it seems that the issue related to not correctly updating the underlying row model on change of the DropDownList. On each change of the DropDownList you should find the dataItem of the current row and set the current value using the set method. 

    For convenience I updated the provided project with the above change and attached it to the current thread.

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top