backbone.validation icon indicating copy to clipboard operation
backbone.validation copied to clipboard

It would be useful to accept `labels` values as functions

Open patatepartie opened this issue 9 years ago • 1 comments

When using the label labelFormatter, the value of each label can only be a string:

var Model = Backbone.Model.extend({
  validation: {
    someAttribute: {
      required: true
    }
  },

  labels: {
    someAttribute: 'Custom label'
  }
});

There are some cases were we may want to have a function executed when building the error message. One of those is having internationalised labels depending on a preference of the user.

This would look like:

var Model = Backbone.Model.extend({
  validation: {
    someAttribute: {
      required: true
    }
  },

  labels: {
    someAttribute: function() {
      return 'Dynamic custom label';
    }
  }
});

patatepartie avatar May 28 '15 15:05 patatepartie

This looks so useful! Can someone submit this PR?

eugenet8k avatar Oct 13 '17 20:10 eugenet8k