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

MVVM model validation

4 Answers 198 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Marcel asked on 06 Jun 2013, 12:56 PM
Hello,

I created a small SPA using Kendo web and the MVVM pattern, but i'm having problems getting validation to work.
So i have a view which binds to a viewmodel using kendo.bind(view, viewmodel).
and example of a domain object (client side) would be like this:
var User = kendo.data.Model.define({
    id: "id",
    fields: {       
        id: {
            editable: false,
            nullable: true
        },
        username: {
            type: "string",
            validation: {
                required: true
            },
            defaultValue: ""
        },
        password: {
            type: "string",
            validation: {
                required: true
            },
            defaultValue: ""
        }
    }
});

and my viewmodel:
var vmLogin = function () {
    var _userName = "";
    var _password = "";
 
    var _user = new User();
    
    var _submitLogin = function () {
    }
 
    var _init = function () {
    }
 
    return {
        Init: _init,
        User: _user,
        Submit: _submitLogin
    }
}

I'm using data-bind in my view to bind to my viewmodel.
Is it possible to apply a Kendo validator to my view using the rules from my Model ?

Thanks in advance.

4 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 07 Jun 2013, 04:53 PM
Hello Marcel,

Kendo Validator works on the basis of validation attributes. In case you use widgets such as editable Grid, the framework automatically attaches the attributes to the corresponding input elements.

When working with standard HTML elements and MVVM, it is responsibility of the developer to put the attributes and initialize the validator.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
sai
Top achievements
Rank 1
answered on 12 Aug 2013, 01:04 PM
thanks Alexander. It worked!
0
Tharsis-it
Top achievements
Rank 2
answered on 23 Apr 2014, 02:12 PM
Hi Alexander, 

When you say it is responsibility of the developer to put the attributes and initialize the validator, you mean that it should be done directly in the HTML/Template or is there some way to make it dynamic and get the values ​​specified in the model? 

Please could you give me an example? 

Thank you very much. 

Alejandro -.
0
Alexander Valchev
Telerik team
answered on 25 Apr 2014, 08:09 AM
Hi Alejandro,

The validation rules defined in the model will be taken into account only if you use a widget with build-in editing such as Kendo Grid. (example)
In case you plant to use template/html/MVVM it is responsibility of the developer to put the corresponding HTML5 validation attributes to the input elements so the validator can validate them. For more information and code samples which demonstrates how to configure and use Kendo Validator please check this help topic.

Regards,
Alexander Valchev
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
Marcel
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
sai
Top achievements
Rank 1
Tharsis-it
Top achievements
Rank 2
Share this question
or