angular using angular-translate for the global validation message

advertisements

Validation Message can be configured globally like here http://docs.angular-formly.com/v5.2.1/docs/formlyvalidationmessages

I like to use the translation filter, so that written validation errors are translated in the configured language. Does someone know how this can be done?


Assuming your using something like this to set your validation message:

var field = {
  type: 'whatever',
  templateOptions: {
    pattern: /some_crazyPattern/,
    patternValidationMessage: '"Needs to match " + options.templateOptions.pattern'
  }
};

Using angular translate, within the js code $translate can be used for this:

$translate('some.message').then(function(response) {
  var field = {
    type: 'whatever',
    templateOptions: {
      pattern: /some_crazyPattern/,
      patternValidationMessage: response.some.message + 'options.templateOptions.pattern'
    }
  };
});

Is this helping?