Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a function als validation message #591

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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?

@mac2000
Copy link

mac2000 commented May 30, 2016

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.

None yet

3 participants