{"action":"created","issue":{"url":"https://api.github.com/repos/gcanti/tcomb-form/issues/83","labels_url":"https://api.github.com/repos/gcanti/tcomb-form/issues/83/labels{/name}","comments_url":"https://api.github.com/repos/gcanti/tcomb-form/issues/83/comments","events_url":"https://api.github.com/repos/gcanti/tcomb-form/issues/83/events","html_url":"https://github.com/gcanti/tcomb-form/issues/83","id":62497777,"number":83,"title":"Conditional required fields","user":{"login":"nanodocumet","id":250255,"avatar_url":"https://avatars.githubusercontent.com/u/250255?v=3","gravatar_id":"","url":"https://api.github.com/users/nanodocumet","html_url":"https://github.com/nanodocumet","followers_url":"https://api.github.com/users/nanodocumet/followers","following_url":"https://api.github.com/users/nanodocumet/following{/other_user}","gists_url":"https://api.github.com/users/nanodocumet/gists{/gist_id}","starred_url":"https://api.github.com/users/nanodocumet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nanodocumet/subscriptions","organizations_url":"https://api.github.com/users/nanodocumet/orgs","repos_url":"https://api.github.com/users/nanodocumet/repos","events_url":"https://api.github.com/users/nanodocumet/events{/privacy}","received_events_url":"https://api.github.com/users/nanodocumet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-17T19:35:10Z","updated_at":"2015-03-18T16:41:42Z","closed_at":null,"body":"Hi there,\r\n\r\nImagine a form such as:\r\n\r\n1) Name (required) - string\r\n2) Email (optional) - string\r\n3) Favorite sport (required) - select with option for other\r\n4) Other Favorite sport (optional) - to be required when Favorite sport is **Other**, otherwise optional.\r\n5) Favorite color (required) - select with option for other\r\n6) Other Favorite color (optional) - to be required when Favorite color is **Other**, otherwise optional.\r\n\r\nHow can the following be achieved?\r\n1) Show the conditional required fields accordingly. Other Favorite sport and Other Favorite color when the **Other** option is picked.\r\n2) Form should be valid when there are no values for the **Other** fields and the values of the favorite things are not \"Other\". This probably leads to mark the **Other** fields as `t.maybe(t.Str)`\r\n3) However, with \"maybe\" the labels show with \"(optional)\" at the end, I know I can set the label for those fields manually, but it will be nice if they get updated accordingly.\r\n4) Notice that there could be more than just 1 conditional, thus, logic could be complicated if we use a the predicate and treat everything as a subtype. I took a look at the example from the docs \"Advanced form validation Struct subtypes\" but it still fails on items 1 and 3.\r\n\r\nThus, is it possible to change a field from `t.maybe(t.Str)` to `t.Str` at runtime? That way, all the goodness of required fields will come for free (labels, validations, errors)\r\n\r\nJust doing the hide/show of the field based on the option picked for the select will make the **Other** fields pass the form validation if they are empty when using `t.maybe`.\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/gcanti/tcomb-form/issues/comments/83051896","html_url":"https://github.com/gcanti/tcomb-form/issues/83#issuecomment-83051896","issue_url":"https://api.github.com/repos/gcanti/tcomb-form/issues/83","id":83051896,"user":{"login":"nanodocumet","id":250255,"avatar_url":"https://avatars.githubusercontent.com/u/250255?v=3","gravatar_id":"","url":"https://api.github.com/users/nanodocumet","html_url":"https://github.com/nanodocumet","followers_url":"https://api.github.com/users/nanodocumet/followers","following_url":"https://api.github.com/users/nanodocumet/following{/other_user}","gists_url":"https://api.github.com/users/nanodocumet/gists{/gist_id}","starred_url":"https://api.github.com/users/nanodocumet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nanodocumet/subscriptions","organizations_url":"https://api.github.com/users/nanodocumet/orgs","repos_url":"https://api.github.com/users/nanodocumet/repos","events_url":"https://api.github.com/users/nanodocumet/events{/privacy}","received_events_url":"https://api.github.com/users/nanodocumet/received_events","type":"User","site_admin":false},"created_at":"2015-03-18T16:41:42Z","updated_at":"2015-03-18T16:41:42Z","body":"Thanks Giulio for your prompt responses! I will check your second response and let you know how it goes.\r\n\r\nThanks!"}}