Validate business rules without direct binding to a HTML field

4 posts, 0 answers
  1. Pavel
    Pavel avatar
    15 posts
    Member since:
    May 2012

    Posted 04 Mar 2015 Link to this post

    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.

  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 06 Mar 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Pavel
    Pavel avatar
    15 posts
    Member since:
    May 2012

    Posted 06 Mar 2015 in reply to Alexander Popov Link to this post

    Alexander, thank you.
    Haven't you plans for adding a business rules validator?
    I think it would be a very nice feature.
  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 09 Mar 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready