Skip to content

Conversation

@hoetmaaiers
Copy link

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?

@marchenko1985
Copy link

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();
        }
    }
});

@phazlett
Copy link

phazlett commented Dec 4, 2016

Thanks @mac2000, I needed to add i18n support to validation messages and your solution works like a champ!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants