{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"params":[],"settings":""},"next":{"description":"","pages":[]},"title":"formlyValidationMessages","type":"basic","slug":"formlyvalidationmessages","excerpt":"service","body":"This service allows you to control what messages gets added to each field's `validation.messages` which can ultimately be used in an `ng-messages` context to great effect. It has a `messages` property which is what is used to attach the `messages` to the field's config. The messages here should be set as angular expressions (or functions) similar to how `expressionProperties` or `validators` works. You can always interact with `messages` on your own, but there are two helper methods in this service\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"addTemplateOptionValueMessage\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"formlyValidationMessages.addTemplateOptionValueMessage(name, prop, prefix, suffix, alternate);\\n// for example\\nformlyValidationMessages.addTemplateOptionValueMessage('max', 'max', 'The max value allowed is', '', 'Too big');\\nformlyValidationMessages.addTemplateOptionValueMessage('minlength', 'minlength', '', 'is the minimum length', 'Too short');\\nformlyValidationMessages.addTemplateOptionValueMessage('pattern', 'patternValidationMessage', '', '', 'Invalid Input');\\n\\n// the last could be used like so:\\nvar field = {\\n  type: 'whatever',\\n  templateOptions: {\\n    pattern: /some_crazyPattern/,\\n    patternValidationMessage: '\\\"Needs to match \\\" + options.templateOptions.pattern'\\n  }\\n};\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"addStringMessage\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"formlyValidationMessages.addStringMessage(name, string);\\n// for example\\nformlyValidationMessages.addStringMessage('required', 'This field is required');\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"messages\"\n}\n[/block]\nThe methods above simply create a function and add it to the `messages` property on this service. So, you can do this yourself for maximum flexibility\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"formlyValidationMessages.messages.required = getRequiredMessage;\\n\\nfunction getRequiredMessage($viewValue, $modelValue, scope) {\\n  if (scope.data.useGenericMessage) {\\n    return 'This field is required';\\n  } else {  \\n\\t  return scope.to.label + ' is required';\\n  }\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:html]\n{\n  \"html\": \"<hr />\\n<a href=\\\"https://app.codesponsor.io/link/PKGFLnhDiFvsUA5P4kAXfiPs/formly-js/angular-formly\\\" rel=\\\"nofollow\\\"><img src=\\\"https://app.codesponsor.io/embed/PKGFLnhDiFvsUA5P4kAXfiPs/formly-js/angular-formly.svg\\\" style=\\\"width: 888px; height: 68px;\\\" alt=\\\"Sponsor\\\" /></a>\\n\"\n}\n[/block]","updates":[],"order":32,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"56d91c5807ae190b00004486","category":{"sync":{"isSync":false,"url":""},"pages":["56d91c5807ae190b00004483","56d91c5807ae190b00004484","56d91c5807ae190b00004485","56d91c5807ae190b00004486"],"title":"API","slug":"api","order":3,"from_sync":false,"reference":false,"_id":"56d91c5507ae190b00004467","version":"56d91c5507ae190b00004460","createdAt":"2015-03-28T04:12:21.318Z","project":"5515ba4981faf83900d2b10c","__v":1},"project":"5515ba4981faf83900d2b10c","version":{"version":"8.0.0","version_clean":"8.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["56d91c5507ae190b00004464","56d91c5507ae190b00004465","56d91c5507ae190b00004466","56d91c5507ae190b00004467","56d91c5507ae190b00004468"],"_id":"56d91c5507ae190b00004460","releaseDate":"2016-03-04T05:25:41.052Z","__v":1,"createdAt":"2016-03-04T05:25:41.052Z","project":"5515ba4981faf83900d2b10c"},"createdAt":"2015-03-28T18:24:28.238Z","githubsync":"","user":"54e3723b8ef7552300409bf4","__v":1}

formlyValidationMessages

service

This service allows you to control what messages gets added to each field's `validation.messages` which can ultimately be used in an `ng-messages` context to great effect. It has a `messages` property which is what is used to attach the `messages` to the field's config. The messages here should be set as angular expressions (or functions) similar to how `expressionProperties` or `validators` works. You can always interact with `messages` on your own, but there are two helper methods in this service [block:api-header] { "type": "basic", "title": "addTemplateOptionValueMessage" } [/block] [block:code] { "codes": [ { "code": "formlyValidationMessages.addTemplateOptionValueMessage(name, prop, prefix, suffix, alternate);\n// for example\nformlyValidationMessages.addTemplateOptionValueMessage('max', 'max', 'The max value allowed is', '', 'Too big');\nformlyValidationMessages.addTemplateOptionValueMessage('minlength', 'minlength', '', 'is the minimum length', 'Too short');\nformlyValidationMessages.addTemplateOptionValueMessage('pattern', 'patternValidationMessage', '', '', 'Invalid Input');\n\n// the last could be used like so:\nvar field = {\n type: 'whatever',\n templateOptions: {\n pattern: /some_crazyPattern/,\n patternValidationMessage: '\"Needs to match \" + options.templateOptions.pattern'\n }\n};", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "addStringMessage" } [/block] [block:code] { "codes": [ { "code": "formlyValidationMessages.addStringMessage(name, string);\n// for example\nformlyValidationMessages.addStringMessage('required', 'This field is required');", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "messages" } [/block] The methods above simply create a function and add it to the `messages` property on this service. So, you can do this yourself for maximum flexibility [block:code] { "codes": [ { "code": "formlyValidationMessages.messages.required = getRequiredMessage;\n\nfunction getRequiredMessage($viewValue, $modelValue, scope) {\n if (scope.data.useGenericMessage) {\n return 'This field is required';\n } else { \n\t return scope.to.label + ' is required';\n }\n}", "language": "javascript" } ] } [/block] [block:html] { "html": "<hr />\n<a href=\"https://app.codesponsor.io/link/PKGFLnhDiFvsUA5P4kAXfiPs/formly-js/angular-formly\" rel=\"nofollow\"><img src=\"https://app.codesponsor.io/embed/PKGFLnhDiFvsUA5P4kAXfiPs/formly-js/angular-formly.svg\" style=\"width: 888px; height: 68px;\" alt=\"Sponsor\" /></a>\n" } [/block]