Knockout-Validation
Knockout-Validation copied to clipboard
Allow a function als validation message
By allowing a function in the validationMessage binding, it is possible to for example use another knockout observable as the validation message. The following example is used in our application for dynamically updating the validation message. I18n is provided by i18next.js for the whole application.
required: {
message: function() {
return i18n.get('validation_required')
}
}
Not sure if any tests are written for this custom binding?
Seems that this PR is not appropriate anymore, while playing around and trying to reimplement this, found appropriate tests, so if you wish to use messages as functions you may do something like this:
self.dateBirth = ko.observable().extend({
required: {
params: true,
message: function (params, observable) {
return self.resources.errorMessageDateBirthRequired.label();
}
}
});
Thanks @mac2000, I needed to add i18n support to validation messages and your solution works like a champ!