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

change event should return value in new version

4 Answers 96 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Janusz
Top achievements
Rank 1
Janusz asked on 16 Feb 2016, 09:14 AM

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>

4 Answers, 1 is accepted

Sort by
0
Janusz
Top achievements
Rank 1
answered on 16 Feb 2016, 09:33 AM

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

0
Janusz
Top achievements
Rank 1
answered on 18 Feb 2016, 07:39 AM

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>

0
Georgi Krustev
Telerik team
answered on 18 Feb 2016, 08:51 AM
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
0
Janusz
Top achievements
Rank 1
answered on 19 Feb 2016, 11:31 AM

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)

 

Tags
DropDownList
Asked by
Janusz
Top achievements
Rank 1
Answers by
Janusz
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or