forked from Knockout-Contrib/Knockout-Validation
-
Notifications
You must be signed in to change notification settings - Fork 32
Override Error Messages
vongillern edited this page Jan 9, 2013
·
1 revision
You can override the default message for a validation on a per property basis. Here is how you configure the extend call:
ko.validation.rules['mustEqual'] = {
validator: function (val, otherVal) {
return val === otherVal;
},
message: 'The field must equal {0}'
};
ko.validation.registerExtenders();
//if not modifying the default message, you would call like this:
// viewModel.PercentSum.extend({ mustEqual: 100 });
//if you want to override the message, you need to move your validation parameter into the "params" field
viewModel.PercentSum.extend({ mustEqual: { params: 100, message: "Percentages must add to 100" } });