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

Custom Editor For a Bound Property and validation

6 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alain
Top achievements
Rank 1
Alain asked on 07 Jan 2015, 03:10 PM
Based on your documentation example (http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/editor-templates), I replaced the DropDownList by a ComboBox element, used it with an editable Grid displaying orders and tried to achieve following scenario:
-when I add a new Order, I want the Grid to switch in inline edit mode with ComboBox having no item selected (means displaying Placeholder text)
-use of client validation to ensure that an Employee has been selected in the ComboBox

I ran in 2 issues:
-If I did not set a DefaultValue for my model field in the View I got an error saying that "employee is not defined". So I set a DefaultValue with a new instance of Employee. But it affected my Combobox comportment by displaying a "0" (because EmployeeID in new instance of Employee was not set and is a type of int)
-I was unable to set client validation by using annotation in Order model for Employee property, because dat-val-* was not added to Combobox element (worked fine for other element like textbox)

So, what am I doing wrong? What am I missing? Please provide sample code.

Thanks
Alain

6 Answers, 1 is accepted

Sort by
0
Alain
Top achievements
Rank 1
answered on 08 Jan 2015, 10:52 AM
Would it be a better approach to use ForeignKeyColumn to handle null value (instead of Bound Property Column) and display a "Please select" in the ComboBox ?

Thanks
Alain
0
Petur Subev
Telerik team
answered on 09 Jan 2015, 05:43 PM

Hello Alain,

I would suggest you to use ID column instead of "nested object" column. You just need to set the data-value-primitive options of the ComboBox to true. And Also specify that the value field of the placeholder of the ComboBox is an empty string or 0,  and the default vlaue for that item is also empty string or 0.

Here is a simplified example that should give you the idea:

http://dojo.telerik.com/@pesho/uRaQU/2

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Alain
Top achievements
Rank 1
answered on 12 Jan 2015, 04:40 PM
Thanks for your reply

I extended your simple example. I want to validate user input, more than just having the Position field as required. As this field is a ComboxBox in editing mode, how can I ensure that user writes only values contained in the list?

I tried to implement a custom validation rule based on your demo (http://demos.telerik.com/aspnet-mvc/grid/editing-custom-validation) but I am not able to get the validation fired.

I am using Kendo UI Server-Side wrappers (Html.Kendo().ComboBox()), C# models () and JS (to register custom validation rules). Do I need to strickly follow your simplified example a only use JS ?

Regards
Alain
0
Petur Subev
Telerik team
answered on 14 Jan 2015, 01:09 PM

Hello Alain,

ComboBox's purpose is to allow user to pick item from the list or to type cusotm value, this is why it is called ComboBox. If you want to restrict the user to only pick value from a list consider using a DropDownList. I assume  you were looking for the ComboBox becase it has filtering but notice the DropDownList also sports such filter

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Alain
Top achievements
Rank 1
answered on 14 Jan 2015, 01:57 PM
Hi Petur,

You are right, DropDownList might be a better choice to restrict the user to only pick value from a list. But then, how can I validate user choice (to be different from Option Label) ? I've tried to use validation rules (with data annotations) but the validation is not fired and tooltips are never display for the DropDownList.

Regards
Alain
0
Alain
Top achievements
Rank 1
answered on 15 Jan 2015, 03:00 PM
Thanks for your help. 

I finally manage to make it work. The main issue with custom validation and data annotations was that some data-val-* attribute were not correctly generated. Using ComboBoxFor or DropDownListFor helpers instead of (ComboBox or DropDownList) helped me to solved the issue.

Regards
Alain
Tags
Grid
Asked by
Alain
Top achievements
Rank 1
Answers by
Alain
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or