{"action":"created","issue":{"url":"https://api.github.com/repos/mozilla-services/react-jsonschema-form/issues/145","repository_url":"https://api.github.com/repos/mozilla-services/react-jsonschema-form","labels_url":"https://api.github.com/repos/mozilla-services/react-jsonschema-form/issues/145/labels{/name}","comments_url":"https://api.github.com/repos/mozilla-services/react-jsonschema-form/issues/145/comments","events_url":"https://api.github.com/repos/mozilla-services/react-jsonschema-form/issues/145/events","html_url":"https://github.com/mozilla-services/react-jsonschema-form/issues/145","id":149362936,"number":145,"title":"Custom field validation","user":{"login":"n1k0","id":41547,"avatar_url":"https://avatars1.githubusercontent.com/u/41547?v=4","gravatar_id":"","url":"https://api.github.com/users/n1k0","html_url":"https://github.com/n1k0","followers_url":"https://api.github.com/users/n1k0/followers","following_url":"https://api.github.com/users/n1k0/following{/other_user}","gists_url":"https://api.github.com/users/n1k0/gists{/gist_id}","starred_url":"https://api.github.com/users/n1k0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/n1k0/subscriptions","organizations_url":"https://api.github.com/users/n1k0/orgs","repos_url":"https://api.github.com/users/n1k0/repos","events_url":"https://api.github.com/users/n1k0/events{/privacy}","received_events_url":"https://api.github.com/users/n1k0/received_events","type":"User","site_admin":false},"labels":[{"id":300444387,"url":"https://api.github.com/repos/mozilla-services/react-jsonschema-form/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-04-19T06:35:27Z","updated_at":"2018-03-06T04:32:52Z","closed_at":"2016-05-09T14:16:06Z","author_association":"MEMBER","body":"Refs #144 and possibly other issues.\n\nWe should be able to define custom validation logic for fields:\n\n``` js\nconst schema = {\n  type: \"object\",\n  properties: {\n    pass1: {type: \"string\", minLength: 8},\n    pass2: {type: \"string\", minLength: 8},\n  }\n};\n\nfunction validate({pass1, pass2}, error) {\n  if (pass1 !== pass2) {\n    return error(\"Passwords don't match\");\n  }\n}\n\nconst uiSchema = {\n  \"ui:validate\": validate,\n  pass1: {\"ui:widget\": \"password\"},\n  pass2: {\"ui:widget\": \"password\"},\n};\n\nrender(<Form schema={schema} uiSchema={uiSchema} />);\n```\n\nWe should also be able to registering these, as we do for custom fields and widgets. The `error` function should handle field error contextualization, so it might be bound appropriately with the field path. \n\nNot entirely sure these validators should be part of uiSchema or have their own container:\n\n``` js\nconst validatorSchema = {\n  root: validate\n};\n\nrender(<Form schema={schema} validatorSchema={validatorSchema} />);\n```\n\nOr simply \n\n``` js\nfunction validate({pass1, pass2}, error) {\n  if (pass1 !== pass2) {\n    return error(\"root.pass2\", \"Passwords don't match\");\n  }\n}\n\nrender(<Form schema={schema} customValidate={validate} />);\n```\n\nWhere the function will always be passed the whole `formData`, and the developer will have to specify the location of the error by hand.\n\nLast, it appears more and more that validation and error handling could be made at the field level, as suggested by @rhgb in https://github.com/mozilla-services/react-jsonschema-form/pull/132#issuecomment-209976438, and so we would propagate errors a little like we propagate `formData` up the tree. That would obviously require some heavy refactoring, but quite possibly for the better. Also, that would allow defining custom validation logic and error propagation right from custom fields, which would be definitely convenient.\n\nDecisions, decisions. Thoughts?\n"},"comment":{"url":"https://api.github.com/repos/mozilla-services/react-jsonschema-form/issues/comments/370659400","html_url":"https://github.com/mozilla-services/react-jsonschema-form/issues/145#issuecomment-370659400","issue_url":"https://api.github.com/repos/mozilla-services/react-jsonschema-form/issues/145","id":370659400,"user":{"login":"mattblackdev","id":5210361,"avatar_url":"https://avatars3.githubusercontent.com/u/5210361?v=4","gravatar_id":"","url":"https://api.github.com/users/mattblackdev","html_url":"https://github.com/mattblackdev","followers_url":"https://api.github.com/users/mattblackdev/followers","following_url":"https://api.github.com/users/mattblackdev/following{/other_user}","gists_url":"https://api.github.com/users/mattblackdev/gists{/gist_id}","starred_url":"https://api.github.com/users/mattblackdev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattblackdev/subscriptions","organizations_url":"https://api.github.com/users/mattblackdev/orgs","repos_url":"https://api.github.com/users/mattblackdev/repos","events_url":"https://api.github.com/users/mattblackdev/events{/privacy}","received_events_url":"https://api.github.com/users/mattblackdev/received_events","type":"User","site_admin":false},"created_at":"2018-03-06T04:32:52Z","updated_at":"2018-03-06T04:32:52Z","author_association":"NONE","body":"@glasserc Thanks for the reply. You make a great point and my experience has been as you predicted. What I ended up doing so far is my 2nd option above, disabling the submit and having the custom field render it's own errors. It's feels crude and limited. I think what our project needs is as you say, a custom or more robust way to define a schema then we can generate the JSON Schema schema for editing data via react-jsonschema-form. However, I'm afraid this might take us down a path that abandons react-jsonshema-form all together."}}
{"actor":{"display_login":"mattblackdev"}}