change event should return value in new version

5 posts, 0 answers
  1. Janusz
    Janusz avatar
    12 posts
    Member since:
    Jul 2012

    Posted 16 Feb Link to this post

    I've noticed then in new version (2016.1.112) of component KendoDropDownList was changed the logic of the change event. In previous version (2015. 3.1111) in the change function I don't have to return the proper value. Below is the razor code that works fine.

    ...................
                    <tr>
                        <td class="required-label">
                            @Html.LabelFor(m => m.FolderId)
                        </td>
                        <td>
                            @(Html.Kendo().DropDownList().Name("FolderId")
                                  .HtmlAttributes(new { @class = "select-list" })
                                  .OptionLabel("-- WYBIERZ RODZAJ ZGŁOSZENIA --")
                                  .DataTextField("Description")
                                  .DataValueField("Symbol")
                                  .DataSource(source => source.Read(read => read.Action("GetFolders", "Zgloszenia"))))
                        </td>
                    </tr>
                    <tr>
                        <td class="required-label">
                            @Html.LabelFor(m => m.Subject)
                        </td>
                        <td>
                            @Html.Kendo().TextBoxFor(m => m.Subject).HtmlAttributes(new { @class = "textboxlong" })
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Html.LabelFor(m => m.ForeignCode)
                        </td>
                        <td>
                            @Html.Kendo().TextBoxFor(m => m.ForeignCode)
                        </td>
                    </tr>
                    <tr>
                        <td class="required-label">
                            @Html.LabelFor(m => m.ProductId)
                        </td>
                        <td>
                            @(Html.Kendo().DropDownList().Name("ProductId")
                                  .HtmlAttributes(new { @class = "select-list", data_val = "true", data_val_required = "Musisz wybrać odpowiedni program z listy" })
                                  .OptionLabel("-- Wybierz produkt, którego dotyczy zgłoszenie --")
                                  .DataTextField("DescriptionValid")
                                  .DataValueField("Symbol")
                                  .DataSource(source => source.Read(read => read.Action("GetProducts", "Zgloszenia").Data("filterProducts"))
                                      .ServerFiltering(true))
                                  .Enable(false)
                                  .AutoBind(true)
                                  .CascadeFrom("FolderId")
                                  )
                        </td>
                    </tr>
    ..................
    <script>
        $(function () {
            var folderObj = $("#FolderId");
            if (folderObj) {
                folderObj.data("kendoDropDownList").setOptions({
                    change: function (e) {
                        var folderVal = folderObj.val();
                        if (folderVal == "ZSER") {
                            $("#versionLabel").removeClass("required-label");
                            $("#Version").removeAttr("data-val-required");
                        } else {
                            $("#versionLabel").addClass("required-label");
                            $("#Version").attr("data-val-required", "Podanie wersji programu jest wymagane");
                        }
                    }
               });
            }
        });
    </script>
     

     In the new version it turned out that my dropdownlist doesn't work, operator cannot choose the item. Exactly after clicking on, it drop down, but after choosing the item it still remains the previous one. It looks like someone has disabled the control. I've found that if add to my function return value, everything will be OK.  My question is if this logic will be developed in the future? Should I always remember to return the proper value? Below is new version of this function.

    <script>
        $(function () {
            var folderObj = $("#FolderId");
            if (folderObj) {
                folderObj.data("kendoDropDownList").setOptions({
                    change: function (e) {
                        var folderVal = folderObj.val();
                        if (folderVal == "ZSER") {
                            $("#versionLabel").removeClass("required-label");
                            $("#Version").removeAttr("data-val-required");
                        } else {
                            $("#versionLabel").addClass("required-label");
                            $("#Version").attr("data-val-required", "Podanie wersji programu jest wymagane");
                        }
                    }
                    return folderVal;
                });
            }
        });
    </script>

  2. Janusz
    Janusz avatar
    12 posts
    Member since:
    Jul 2012

    Posted 16 Feb in reply to Janusz Link to this post

    I should add that this return line is necessary only when there is another dropdownlist which have the dependency argument CascadeFrom.

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Janusz
    Janusz avatar
    12 posts
    Member since:
    Jul 2012

    Posted 18 Feb in reply to Janusz Link to this post

    The previous solution doesn't always works properly. So I must change it. Maybe someone has the same problem and this code below helps him. Instead of setOptions I use the recommended way (JQuery bind method)

    <script>
            var folderObj = $("#FolderId").data("kendoDropDownList");
            if (folderObj) {
                folderObj.bind("change", function (e) {
                    var folderVal = folderObj.value();
                    if (folderVal == "ZSER") {
                        $("#versionLabel").removeClass("required-label");
                        $("#Version").removeAttr("data-val-required");
                    } else {
                        $("#versionLabel").addClass("required-label");
                        $("#Version").attr("data-val-required", "Podanie wersji programu jest wymagane");
                    }
                });
            }
        });
    </script>

  5. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 18 Feb Link to this post

    Hello Janusz,

    It always better to use the widget's API when you are using its events cycle.

    As to the requirement to return value from within the "change" event handler, I would like to disagree with that statement. When the "change" event is triggered, we do not care about the result of that function: It is a callback that is not preventable, hence "return value" is not relevant in this case.

    If you are experiencing any issues that you believe are erroneous, please send us a repro demo that demonstrates them. Thus we will be able to review them and follow you with more details.

    Regards,
    Georgi Krustev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Janusz
    Janusz avatar
    12 posts
    Member since:
    Jul 2012

    Posted 19 Feb in reply to Georgi Krustev Link to this post

    Thanks for your reply. You are right - return value doesn't have any influence on it. It's my fault - I've left the old version of kendo library. So if anyone use method setOptions in such cases he should change it on JQuery bind function. 

    Regards Jaśkowiec Józef

    Rekord (Poland)

     

Back to Top
UI for ASP.NET MVC is VS 2017 Ready