{"action":"created","issue":{"url":"https://api.github.com/repos/forms-js/forms-js/issues/2","labels_url":"https://api.github.com/repos/forms-js/forms-js/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/forms-js/forms-js/issues/2/comments","events_url":"https://api.github.com/repos/forms-js/forms-js/issues/2/events","html_url":"https://github.com/forms-js/forms-js/pull/2","id":60551208,"number":2,"title":"Interfaces","user":{"login":"bvaughn","id":29597,"avatar_url":"https://avatars.githubusercontent.com/u/29597?v=3","gravatar_id":"","url":"https://api.github.com/users/bvaughn","html_url":"https://github.com/bvaughn","followers_url":"https://api.github.com/users/bvaughn/followers","following_url":"https://api.github.com/users/bvaughn/following{/other_user}","gists_url":"https://api.github.com/users/bvaughn/gists{/gist_id}","starred_url":"https://api.github.com/users/bvaughn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bvaughn/subscriptions","organizations_url":"https://api.github.com/users/bvaughn/orgs","repos_url":"https://api.github.com/users/bvaughn/repos","events_url":"https://api.github.com/users/bvaughn/events{/privacy}","received_events_url":"https://api.github.com/users/bvaughn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-03-10T19:00:21Z","updated_at":"2015-03-10T21:33:34Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/forms-js/forms-js/pulls/2","html_url":"https://github.com/forms-js/forms-js/pull/2","diff_url":"https://github.com/forms-js/forms-js/pull/2.diff","patch_url":"https://github.com/forms-js/forms-js/pull/2.patch"},"body":"Here's an example of how we could (potentially) represent the validation schema outlined [in the shared Google doc](https://docs.google.com/document/d/1cghvrZXMbLzwlG181AuBXzhCR3fmeY06jR17OnID1wA/edit#) by way of TypeScript interfaces.\r\n\r\nOpen questions for discussion:\r\n* The ability to specify either a value (e.g. `required: true`) *or* an object (`required: { value: true, failureMessage: \"This is a custom error\" }`) is certainly convenient from a user perspective but it also complicates our interface definitions. I assume this is okay, but it seems worth confirming.\r\n* I collapsed the `constraints` field because it felt unnecessary/redundant. Is this okay?\r\n\r\nThe below interfaces describe a validation object like this:\r\n\r\n```js\r\nvar validationSchema = {\r\n  fields: {\r\n    username: {\r\n      required: true,\r\n      pattern: {\r\n        value: /.+@.+\\..+/,\r\n        failureMessage: \"%s is not a valid email format\"\r\n    },\r\n    username: {\r\n      required: true,\r\n      min: 6,\r\n      pattern: /[0-9]/\r\n    }\r\n  }\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/forms-js/forms-js/issues/comments/78153196","html_url":"https://github.com/forms-js/forms-js/pull/2#issuecomment-78153196","issue_url":"https://api.github.com/repos/forms-js/forms-js/issues/2","id":78153196,"user":{"login":"bvaughn","id":29597,"avatar_url":"https://avatars.githubusercontent.com/u/29597?v=3","gravatar_id":"","url":"https://api.github.com/users/bvaughn","html_url":"https://github.com/bvaughn","followers_url":"https://api.github.com/users/bvaughn/followers","following_url":"https://api.github.com/users/bvaughn/following{/other_user}","gists_url":"https://api.github.com/users/bvaughn/gists{/gist_id}","starred_url":"https://api.github.com/users/bvaughn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bvaughn/subscriptions","organizations_url":"https://api.github.com/users/bvaughn/orgs","repos_url":"https://api.github.com/users/bvaughn/repos","events_url":"https://api.github.com/users/bvaughn/events{/privacy}","received_events_url":"https://api.github.com/users/bvaughn/received_events","type":"User","site_admin":false},"created_at":"2015-03-10T21:33:34Z","updated_at":"2015-03-10T21:33:34Z","body":"@davidlgj I've updated the interfaces and added an example `Validator` and `RequiredValidator`. (Baby steps for discussion.)\r\n\r\n@kentcdodds Looks like using apiCheck for type-validation could potentially work. Two concerns though:\r\n* Using apiCheck would be adding a dependency on a small library. (No offense meant, just that the smaller the library, the greater the chance of future abandonment.) This concern is probably mitigated by the fact that you're the author though. :)\r\n* The way I am currently envisioning types- something that we should actually discuss- is not *just* validation, but *validation and implicit coercion*. For instance, if you tell Forms JS that field \"foo\" is an integer then we should *validate* that it only contains digits (0-9). I was also assuming we'd handle the case where a particular field-template didn't specify an input-type and the resulting value we got was a string that *contained* an integer.\r\n* I was also assuming we'd let users specify integer *or* float whereas I think apiCheck may only support number? (This could be changed, I'm sure.)"}}