{"action":"created","issue":{"url":"https://api.github.com/repos/dobromir-hristov/vuelidate-error-extractor/issues/4","repository_url":"https://api.github.com/repos/dobromir-hristov/vuelidate-error-extractor","labels_url":"https://api.github.com/repos/dobromir-hristov/vuelidate-error-extractor/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/dobromir-hristov/vuelidate-error-extractor/issues/4/comments","events_url":"https://api.github.com/repos/dobromir-hristov/vuelidate-error-extractor/issues/4/events","html_url":"https://github.com/dobromir-hristov/vuelidate-error-extractor/pull/4","id":264723713,"number":4,"title":"Added support for generic messages","user":{"login":"mokkabonna","id":230877,"avatar_url":"https://avatars0.githubusercontent.com/u/230877?v=4","gravatar_id":"","url":"https://api.github.com/users/mokkabonna","html_url":"https://github.com/mokkabonna","followers_url":"https://api.github.com/users/mokkabonna/followers","following_url":"https://api.github.com/users/mokkabonna/following{/other_user}","gists_url":"https://api.github.com/users/mokkabonna/gists{/gist_id}","starred_url":"https://api.github.com/users/mokkabonna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mokkabonna/subscriptions","organizations_url":"https://api.github.com/users/mokkabonna/orgs","repos_url":"https://api.github.com/users/mokkabonna/repos","events_url":"https://api.github.com/users/mokkabonna/events{/privacy}","received_events_url":"https://api.github.com/users/mokkabonna/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-10-11T20:24:03Z","updated_at":"2017-10-24T12:07:01Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/dobromir-hristov/vuelidate-error-extractor/pulls/4","html_url":"https://github.com/dobromir-hristov/vuelidate-error-extractor/pull/4","diff_url":"https://github.com/dobromir-hristov/vuelidate-error-extractor/pull/4.diff","patch_url":"https://github.com/dobromir-hristov/vuelidate-error-extractor/pull/4.patch"},"body":"I have added support for defining messages for generated validator names.\r\n\r\nThis will only be used if the validator does have no exactly matching message.\r\n\r\nYou define them like this:\r\n```js\r\nVue.use(vuelidateErrorExtractor, {\r\n  template: templates.foundation6,\r\n  messages: {\r\n    required: '{attribute} is required'\r\n  },\r\n  genericMessages: [{\r\n    regexp: /.+/,\r\n    message: '{attribute} has an error'\r\n  }]\r\n})\r\n```\r\n\r\nI tried to add testcases, but seems they are not running properly anyway, so did some changes to make them run.\r\n\r\nWould you be willing to add something like this? My inspiration is this issue in my plugin: https://github.com/mokkabonna/vue-vuelidate-jsonschema/issues/4\r\n\r\nThen I could define my generic messages like this:\r\n\r\n```js\r\nVue.use(vuelidateErrorExtractor, {\r\n  template: templates.foundation6,\r\n  messages: {\r\n    required: '{attribute} is required'\r\n  },\r\n  genericMessages: [{\r\n    regexp: /^schemaPattern(\\d+)?$/,\r\n    message: '{schema.title} does not match pattern {schema.pattern}'\r\n  }]\r\n})\r\n```\r\n\r\nThe first message to match the related regexp would be used.\r\n\r\nThis would match against all of:\r\n```js\r\nexport default {\r\n  validations: {\r\n    schemaPattern: pattern('...'),\r\n    schemaPattern2: pattern('...'),\r\n    schemaPattern3: pattern('...')\r\n    ...etc\r\n  }\r\n}\r\n```\r\n\r\nThese would be auto generated by my library.\r\n\r\nWhat do you think? Instead of a regexp it could also be a function that gets passed various params like key, messages, vm and need to return true or false depending on if we sould use the message or not.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/dobromir-hristov/vuelidate-error-extractor/issues/comments/338968198","html_url":"https://github.com/dobromir-hristov/vuelidate-error-extractor/pull/4#issuecomment-338968198","issue_url":"https://api.github.com/repos/dobromir-hristov/vuelidate-error-extractor/issues/4","id":338968198,"user":{"login":"mokkabonna","id":230877,"avatar_url":"https://avatars0.githubusercontent.com/u/230877?v=4","gravatar_id":"","url":"https://api.github.com/users/mokkabonna","html_url":"https://github.com/mokkabonna","followers_url":"https://api.github.com/users/mokkabonna/followers","following_url":"https://api.github.com/users/mokkabonna/following{/other_user}","gists_url":"https://api.github.com/users/mokkabonna/gists{/gist_id}","starred_url":"https://api.github.com/users/mokkabonna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mokkabonna/subscriptions","organizations_url":"https://api.github.com/users/mokkabonna/orgs","repos_url":"https://api.github.com/users/mokkabonna/repos","events_url":"https://api.github.com/users/mokkabonna/events{/privacy}","received_events_url":"https://api.github.com/users/mokkabonna/received_events","type":"User","site_admin":false},"created_at":"2017-10-24T12:07:01Z","updated_at":"2017-10-24T12:07:01Z","author_association":"NONE","body":"Ah, wasn't supposed to end up in the same PR.\r\n\r\nBut your current reduce code does not template values if they are falsy. They fall back to empty string.\r\n\r\nSo if I have minValue -5, it will be templated with empty string instead of -5. So in the changes I did I now rather check that the property is defined. If defined, always return the value, even if falsy. If not defined, return empty string."}}
{"actor":{"display_login":"mokkabonna"}}