Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Allow to pass function to message option #76

Closed
fnky opened this issue Oct 8, 2015 · 1 comment
Closed

Allow to pass function to message option #76

fnky opened this issue Oct 8, 2015 · 1 comment
Milestone

Comments

@fnky
Copy link

fnky commented Oct 8, 2015

The message option is limited to strings, which makes it non-trivial to deal with arrays, objects, etc.

var acceptedValues = [
  { id: 1, name: 'Banana' },
  { id: 2, name: 'Apple' },
  { id: 2, name: 'Mango' }
]

// Fruit is chosen through select which uses ids for value attribute
var constraints = {
  fruit: {
    within: acceptedValues.map(function (o) { return o.id }),
    message: function (id) {
      return '^No such fruit ' + getFruitById(id) + ' available.'
    }
  }
}
@ansman
Copy link
Owner

ansman commented Oct 10, 2015

Interesting, this definitely seems to be in the spirit of validate.js!

@ansman ansman added this to the Next milestone Oct 10, 2015
@ansman ansman closed this as completed in 4f5e210 Oct 10, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants