0

I create a simple model from mapping with knowkoutjs and I want to validate it.

Even if I specify the validation message, the default message is still displayed.

ko.validation.configure({
  parseInputAttributes: true
});

var data = { name: "Joe Shmo", email: "joe@shmo.com" };

var validationMapping = {
  'name': {
      create: function(options) {
         return ko.observable(options.data).extend({required: true,message:"name is required"});
    }
  }
}

var viewModel = ko.validatedObservable(ko.mapping.fromJS(data, validationMapping));
ko.applyBindings(viewModel);

Here is the fiddle

Thanks for your help.

Yoann

Yooz
  • 2,506
  • 21
  • 31

1 Answers1

0

I found the way, my mistake, the syntax of the validation mapping was wrong.

There the good syntax :

var validationMapping = {
'name': {
    create: function(options) {
        return ko.observable(options.data).extend(
        {
          required:{
                     params:true,
                     message:"name is required"
                   }
        });
    }
}
}

I also updated the fiddle.

Matthew Cox
  • 13,566
  • 9
  • 54
  • 72
Yooz
  • 2,506
  • 21
  • 31