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

Validate business rules without direct binding to a HTML field

3 Answers 66 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Pavel
Top achievements
Rank 1
Pavel asked on 04 Mar 2015, 07:20 PM
Hello.

I have a complex viewModel that I need to validate before submiting, but I need not only simple validation rules (such as required field), but also a complex validation that has to do not with html input elements, but with model business rules.

Let me give an example, my viewModel has a timetable property (which represents a study timetable with startHour, endHour, days and trainerId properties), which is an array:

var viewModel = kendo.observable({
    title =
"Example Title",
    timetable: [
        { startHour:
"11:00", endHour: "13:00", days: [ 1 ], trainerId: 1 },
        { startHour:
"12:00", endHour: "14:30", days: [ 3, 5 ], trainerId: 2 }
    ]
});

In this case I need to validate the following: 

  • Timetable contains at least one element
  • Timetable hours don't overlap

This validation is not directly bound to any HTML element, as timetable is a complex property which is rendered using templates.
All kendoValidator examples I've seen work directly with HTML inputs and their attributes.

In other words, is there a possibility to validate the model's business rules, but not HTML inputs?

Thank you.

3 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 06 Mar 2015, 04:18 PM
Hi Pavel,

The Validation is designed to work with input elements and validating just the model is not supported out of the box. Nevertheless, you could achieve similar results by creating a custom validation rule that checks the values of the timetable array. You can then manually execute the rule by calling the Validator's validate or validateInput method. The only requirement is an input element to be present on the page - it is not even necessary to be bound to the observable.

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Pavel
Top achievements
Rank 1
answered on 06 Mar 2015, 08:28 PM
Alexander, thank you.
Haven't you plans for adding a business rules validator?
I think it would be a very nice feature.
0
Alexander Popov
Telerik team
answered on 09 Mar 2015, 09:07 AM
Hello Pavel,

This is currently not on our to-do list, however I would encourage you to submit it as a feature request on the feedback portal. That would allow us to evaluate the idea and prioritize it.

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