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

Allow nulls ( and not have them converted to the empty string)

2 Answers 1652 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Scott Waye
Top achievements
Rank 2
Veteran
Iron
Scott Waye asked on 07 Sep 2016, 08:22 PM

Hi,

I have code similar to this:

http://dojo.telerik.com/OfiMU/7

I want to bind the dropdownlist to a nullable field on the model.  The user should be able to select a value from the list or the select the first optionLabel in order to put the value back to null.  So I added the k-option-label with a value field of null, however when selecting this value in the drop down the model is set to the empty string.  This is a problem as when saved to the database it causes a foreign key exception.   How do I set up the dropDownList to allow it to bind to nullable properties on the model?

 

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 09 Sep 2016, 08:58 AM
Hello Scott,

The ng-model directive works with the value of the underlying SELECT element, which is empty string (""). As a result when the option label is selected, the model value is empty string. Unfortunately, we cannot keep the "null" value as values of the OPTION element is always string.

The solution is either to avoid depending on the null or use k-ng-model:

http://dojo.telerik.com/OfiMU/8

Regards,
Georgi Krustev
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Scott Waye
Top achievements
Rank 2
Veteran
Iron
answered on 09 Sep 2016, 12:04 PM
Thanks, I should have tried that.
Tags
DropDownList
Asked by
Scott Waye
Top achievements
Rank 2
Veteran
Iron
Answers by
Georgi Krustev
Telerik team
Scott Waye
Top achievements
Rank 2
Veteran
Iron
Share this question
or