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

Value before data source read is null?

1 Answer 980 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 11 Aug 2014, 04:23 PM
I have a drop down list using remote data with autoBind set to false.  I can set the initial value and text for the drop down using the value and text properties just fine:

ddlBuilding = $("#ddlBuilding").kendoDropDownList({
    width: 400,
    height: 250,
    dataTextField: "Description",
    dataValueField: "Code",
    value: myBuilding.Code,
    text: myBuilding.Description,
    optionLabel: {
        Description: "",
        Code: ""
    },
    dataSource: {
        transport: {
            read: {
                dataType: 'json',
                url: myServiceUrl
            }
        }
    },
    autoBind: false
}).data("kendoDropDownList");

My issue is that the control does not seem to have a value until the data source is read.  Before the data source is read, $("#ddlBuilding").val() returns NULL and ddlBuilding.value() returns undefined.  Once a user clicks the drop down and the data source is loaded, both of these statements return the proper values.

If a user needs to make changes on a form to other fields, but not to this drop down, how am I to know the proper value if no selection is a valid choice?  Is there a way to tell if the data source for the control has been read or not?

1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 13 Aug 2014, 10:29 AM
Hi Steve,

In order to see if the widget is bound and data is loaded you can check the dataSource data() method that will return either empty array if the widget is not bound, or an array with items if the data is loaded:

$("#dropdownlist").getKendoDropDownList().dataSource.data()

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
DropDownList
Asked by
Steve
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or