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

Dropdownlist dissapears upon re-initialization?

10 Answers 734 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Kjell asked on 07 Mar 2012, 09:28 PM

I have in my form an autocomplete box and a combobox.  I don't populate the comobox box until a selection is made in the autocomplete box.  This has been working fine, but I don't want the user to be able to type in the combobox so I am converting it to a dropdownlist.  After I made the change, my dropdownlist dissapears after the autocomplete box change event fires.  I stripped the code down so all it is doing is re-initializing the dropdownlist, and it still does the same thing.  Here is the code for my autocomplete box:

$("#matterCombo").width(300).kendoAutoComplete({
        minLength: 0,
        autoBind: false,
        dataTextField: "text",
        dataSource: {
            serverPaging: true,
            serverFiltering: true,
            pageSize: 5,
            transport: {
                read: {
                    url: "wsRest.svc/matters/",
                    data: {
                        client: function () {
                            return $("#clientCombo").val();
                        },
                        value: function () {
                            return $("#matterCombo").val();
                        }
                    } //data
                } //read
            } //trans
        }, //ds
        change: function () {
            $("#custom1Combo").kendoDropDownList();
        }
    });

The form loads fine, but when the change event fires, custom1Combo dissapears.

When the page loads, the dropdownlist is initialized like this:

$("#custom1Combo").width(300).kendoDropDownList();

The initial initialization is working fine and I am even able to fill in a default value, but then when I try to update it later it just dissapears.

Help please?

10 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 08 Mar 2012, 09:33 AM
Hi Kjell,

Our widgets are not designed to be initialized twice - why would you need that?

Generally, you can simply remove the display:none style of the DropDownList's wrapper element (which is copied from the #custom1Combo element that has been hidden during the first initialization), but I strongly recommend changing your implementation and avoiding duplicate initialization.

All the best,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Kjell
Top achievements
Rank 1
answered on 08 Mar 2012, 07:37 PM
Ok let me take a step back and go back to what my final goal is.  This dropdownlist is not supposed to populate until a selection is made in an autocomplete, I'll refer to it as the parent.  The following code was working when my dropdownlist was a combobox:

definition for parent combo....
 
change: function () {
    $("#custom1Combo").kendoComboBox({
        dataSource: {
                    autoBind: false,
                    dataTextField: "text",                   
                    transport: {
                        read: {
                            url: "wsRest.svc/custom1/",
                            data: {
                                user: function () {
                                    return userField.value;
                                },
                                client: function () {
                                    return $("#clientCombo").val();
                                },
                                matter: function () {
                                    return $("#matterCombo").val();
                                }
                            }
                        }
                    }
                },
 
 
... more definition for the parent combo box

Again, this was working fine.. BUT the only problem was I did not want the user to be able to type text into the box. So per the documentation, I figured my next move is to convert this to a dropdownlist.  The first thing I tried was just changing "kendoComboBox" to "kendoDropDownList" in hopes that they had the exact same functionality.  That did not work, I assume I am doing something wrong here and just lucked out that it happened to work with the combobox. 
0
Kamen Bundev
Telerik team
answered on 09 Mar 2012, 09:42 AM
Hi Kjell,

The Kendo DropDownList copy the styles from its base element element and since it is hidden the second time, the widget disappears. You can check the Cascading DropDownList example from the Q1 2012 beta to see how to do something similar to your use case.

Greetings,
Kamen Bundev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Kjell
Top achievements
Rank 1
answered on 09 Mar 2012, 06:39 PM
Thanks, I missed that example, I am getting closer.

Is it possible to define the datasource inside the change event for the parent menu, something like this:

change: function () {
                 //update the custom1 datasource
                 custom1List.dataSource = new kendo.data.DataSource({
                     transport: {
                         read: {
                             url: "wsRest.svc/custom1/",
                             data: {
                                 user: function () {
                                     return userField.value;
                                 },
                                 client: function () {
                                     return $("#clientCombo").val();
                                 },
                                 matter: function () {
                                     return $("#matterCombo").val();
                                 }
                             }
                         }
                     }
                 });
             }

or is there something just really wrong about doing it that way?  I apologize for some of the weird questions I am probably asking, I'v been using your silverlight tools for the last ~18 months and don't have much JS experience.  I am like a fish out of water.

You guys also may want to consider releasing some kind of intellisense add-on for visual studio, maybe part of "just code", that would be extremely helpful.
0
Georgi Krustev
Telerik team
answered on 12 Mar 2012, 11:54 AM
Hello Kjell,

 
The DropDownList widget internally wires "requestStart" and "change" event of the DataSource. The DropDownList will stop working once you override the dataSource property. I will recommend you to not reassign the dataSource on the fly. Could you please share why you need to recreate the DataSource on change event of the parent widget? What is the difference between the aforementioned example and your case?

Kind regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Kjell
Top achievements
Rank 1
answered on 12 Mar 2012, 09:06 PM

My webservice results are not structured the same way, basically the web service does the filtering and then it just returns key value pairs to populate the menus. 

I tried doing this instead:

var custom1DataSource = new kendo.data.DataSource({       
     type: "odata",       
     serverFiltering: true,       
     transport: {
         read: {
             url: "wsRest.svc/custom1/",
             data: {
                 user: function () {
                     return userField.value;
                 },
                 client: function () {
                     return $("#clientCombo").val();
                 },
                 matter: function () {
                     return $("#matterCombo").val();
                 }
             }
         }
     }
 });
 
 var custom1List = $("#custom1Combo").kendoDropDownList({       
     dataTextField: "text",
     dataValueField: "value",
     serverFiltering: true,       
     dataSource: custom1DataSource
 }).data("kendoDropDownList");


This almost works.  I put a breakpoint in the web service and I can tell that the filters are passed in properly and the data is being returned, however the dropdownlist just sits there and spins.




0
Georgi Krustev
Telerik team
answered on 14 Mar 2012, 05:43 PM
Hello Kjell,

 
The provided code snippet looks fine at first glance. In order to proceed with the investigation I will need a test project, which replicates the issue.

Kind regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Lee
Top achievements
Rank 2
Bronze
Bronze
Bronze
answered on 21 Nov 2019, 09:37 PM
Was this ever resolved? I have a similar issue. In my case, I have an unknown number of dropdown lists appearing in a modal. The number is determined by the number of records returned when the user clicks a button. That button opens a modal that the dropdown lists exist in. The user may press multipile buttons so there could be 1 dropdown list or there could be 50. Currently, I am initializing the dropdown lists after the modal opens. When the modal is closed and then opened again a call is made to the server. The correct number of input blocks are rendered, each with separate ID's, and then the dropdowns are all reinitialized. This second time is when the list opens and closes immediately.
0
Ivan Danchev
Telerik team
answered on 26 Nov 2019, 01:59 PM

Hello Lee,

It is possible that not properly removing previous instances of the DropDownLists are causing the described behavior. Consider destroying the widgets nested in the modal in its close event handler. For more details on how to destroy widgets, refer to this documentation article.

Give this a try and let us know whether it resolves the issue.

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Lee
Top achievements
Rank 2
Bronze
Bronze
Bronze
answered on 26 Nov 2019, 02:17 PM
Thanks. That worked. When I destroy the widget and reinitialize it it works as expected. 
Tags
DropDownList
Asked by
Kjell
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Kjell
Top achievements
Rank 1
Kamen Bundev
Telerik team
Georgi Krustev
Telerik team
Lee
Top achievements
Rank 2
Bronze
Bronze
Bronze
Ivan Danchev
Telerik team
Share this question
or