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

Validation using the dataSource schema model in a ListView

3 Answers 801 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Shane
Top achievements
Rank 1
Shane asked on 15 May 2012, 03:49 AM
I'm having issues setting up validation on the dataSource's schema.model.fields object. I am following the documentation at: http://www.kendoui.com/documentation/framework/datasource/configuration.aspx as a guide.  It seems that the validation never fires.
 Below is the data source's schema property:
model{
                id"ID",
                fields{
                    Name{
                        editabletrue,
                        nullabletrue,
                        validation {
                            required:true,
                            customRulefunction(input){alert('bad data');}
                        }
                    }
                } 
I would expect that this would mark the field as required, and prevent the form from submitting and then also pop up an alert. 

I have created a jsfiddle with some sample code at:
http://jsfiddle.net/sholder/RxLWS/ 
any guidance on what I have wrong would be most appreciated.

Thanks,
Shane Holder

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 17 May 2012, 08:12 AM
Hi Shane,

As the ListView is using templates, you should manually decorate the html elements with the appropriate validation attributes. An example of how to use ListView widget editing can be found here.

All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Lee
Top achievements
Rank 2
Bronze
Bronze
Bronze
commented on 12 Apr 2022, 06:04 PM

The link above to appropriate validation attributes is no longer valid.
Neli
Telerik team
commented on 15 Apr 2022, 11:18 AM

Hi Lee,

You could take a look at the linked ListView Editing Demo - https://demos.telerik.com/kendo-ui/listview/editing

If you inspect the source (click on 'View source' tab) you will notice the following attribtues: required="required" validationMessage="required"

The attributes are needed to perform the validation. If you try to remove the above mention attributes, the respective field will not be required. Here is a Dojo example where a record without a Product Name can be added to the ListView. 

Regards,

Neli

0
Shane
Top achievements
Rank 1
answered on 17 May 2012, 07:13 PM
Thanks for the information Rosen.  Does this mean that it is not possible to combine using a template and the model property of a schema in a ListView?  I was hoping to keep a separation between the validation code and the html, and generate the validation code for the model by using the DataAnnotations on my .Net model.

Thanks,
Shane Holder
0
Rosen
Telerik team
answered on 18 May 2012, 07:27 AM
Hi Shane,

I'm afraid that as the developer is in charge of template creation, elements cannot be automatically decorated using the model definition.

All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Validation
Asked by
Shane
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Shane
Top achievements
Rank 1
Share this question
or