Knockout.Validation problem

561 views
Skip to first unread message

Jeric John Romero

unread,
Feb 15, 2015, 12:27:13 AM2/15/15
to knock...@googlegroups.com
Hi, i am new to knockout js. Im wondering what's wrong with my viewModel. I want to display my error messages in an alert button. But when it pops out.. it says it is undefined. 
Another things is, i shouldn't be displaying the error messages beside the text input of my html. I tried putting ko.validation.configure({ ... }) above my viewModel but the browser says 
undefined is not a function. What am I missing? 

There are only two input controls in my html page. 

function personViewModel() {
    var self = this;
    self.lastName = ko.observable().extend({ required: { message: 'Last name is required' } });
    self.firstName = ko.observable().extend({ required: { message: 'First name is required' } });

    var firstTabValidation = [
        self.lastName,
        self.firstName
    ];

    self.validateToNext = function () {
        var errors = ko.validation.group(firstTabValidation);
        if (errors().length == 0) {
            alert('Valid');
        } else {
            alert(errors.showAllMessages);
        }
    };
}

ko.applyBindings(new personViewModel());

ilya...@gmail.com

unread,
Feb 17, 2015, 5:03:15 AM2/17/15
to knock...@googlegroups.com
Have you included the validation plugin?

Jeric John Romero

unread,
Feb 17, 2015, 8:54:46 AM2/17/15
to knock...@googlegroups.com, ilya...@gmail.com
I have solved this. I did try to use ko.validation.init instead of ko.validation.configure. However, I can't configure the error message to not show beside my element. 
Reply all
Reply to author
Forward
0 new messages