{"action":"created","issue":{"url":"https://api.github.com/repos/gcanti/tcomb-form/issues/360","repository_url":"https://api.github.com/repos/gcanti/tcomb-form","labels_url":"https://api.github.com/repos/gcanti/tcomb-form/issues/360/labels{/name}","comments_url":"https://api.github.com/repos/gcanti/tcomb-form/issues/360/comments","events_url":"https://api.github.com/repos/gcanti/tcomb-form/issues/360/events","html_url":"https://github.com/gcanti/tcomb-form/issues/360","id":175297046,"number":360,"title":"Full example code for file upload","user":{"login":"sandervanhooft","id":7265703,"avatar_url":"https://avatars.githubusercontent.com/u/7265703?v=3","gravatar_id":"","url":"https://api.github.com/users/sandervanhooft","html_url":"https://github.com/sandervanhooft","followers_url":"https://api.github.com/users/sandervanhooft/followers","following_url":"https://api.github.com/users/sandervanhooft/following{/other_user}","gists_url":"https://api.github.com/users/sandervanhooft/gists{/gist_id}","starred_url":"https://api.github.com/users/sandervanhooft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sandervanhooft/subscriptions","organizations_url":"https://api.github.com/users/sandervanhooft/orgs","repos_url":"https://api.github.com/users/sandervanhooft/repos","events_url":"https://api.github.com/users/sandervanhooft/events{/privacy}","received_events_url":"https://api.github.com/users/sandervanhooft/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-06T16:52:30Z","updated_at":"2016-09-08T09:37:20Z","closed_at":"2016-09-08T09:37:19Z","body":"### Version\r\n\r\nTell us which versions you are using:\r\n\r\n- tcomb-form v0.9.1\r\n- react v15.2.1\r\n\r\n### Expected behaviour\r\n\r\nFile should be uploaded using the example code from #112. It however seems to be incomplete. Is there a complete and working example available? This is what @gcanti has included in #112:\r\n```\r\nvar Type = t.struct({\r\n  caption: t.maybe(t.Str),\r\n  copyright: t.maybe(t.Str),\r\n  reference: t.maybe(t.Str),\r\n  file: t.form.File, // <-- your irreducible\r\n  is_video: t.Bool\r\n});\r\n\r\nvar options = {\r\n  fields: {\r\n    file: {\r\n      type: 'file'\r\n    }\r\n  }\r\n};\r\n\r\nvar App = React.createClass({\r\n\r\n  save() {\r\n    var value = this.refs.form.getValue();\r\n    if (value) {\r\n      console.log(value);\r\n      var fd = new FormData();\r\n      for (var k in value) {\r\n        var v = value[k];\r\n        if (t.form.File.is(v)) {\r\n          fd.append(k, v, v.name);\r\n        } else {\r\n          fd.append(k, v);\r\n        }\r\n      }\r\n      console.log(fd);\r\n      // process form data...\r\n    }\r\n  },\r\n\r\n  render() {\r\n    return (\r\n      <div>\r\n        <Form ref=\"form\"\r\n          type={Type}\r\n          options={options}\r\n        />\r\n        <button className=\"btn btn-primary\" onClick={this.save}>Save</button>\r\n      </div>\r\n    );\r\n  }\r\n\r\n});\r\n\r\nReact.render(<App />, document.getElementById('app'));\r\n```\r\n\r\n### Actual behaviour\r\n\r\nI can't deduce what the `new FormData()` is or where it should be imported from. Additionally, the for-in loop used in the example throws a `guard-for-in` esLint warning."},"comment":{"url":"https://api.github.com/repos/gcanti/tcomb-form/issues/comments/245545651","html_url":"https://github.com/gcanti/tcomb-form/issues/360#issuecomment-245545651","issue_url":"https://api.github.com/repos/gcanti/tcomb-form/issues/360","id":245545651,"user":{"login":"sandervanhooft","id":7265703,"avatar_url":"https://avatars.githubusercontent.com/u/7265703?v=3","gravatar_id":"","url":"https://api.github.com/users/sandervanhooft","html_url":"https://github.com/sandervanhooft","followers_url":"https://api.github.com/users/sandervanhooft/followers","following_url":"https://api.github.com/users/sandervanhooft/following{/other_user}","gists_url":"https://api.github.com/users/sandervanhooft/gists{/gist_id}","starred_url":"https://api.github.com/users/sandervanhooft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sandervanhooft/subscriptions","organizations_url":"https://api.github.com/users/sandervanhooft/orgs","repos_url":"https://api.github.com/users/sandervanhooft/repos","events_url":"https://api.github.com/users/sandervanhooft/events{/privacy}","received_events_url":"https://api.github.com/users/sandervanhooft/received_events","type":"User","site_admin":false},"created_at":"2016-09-08T09:37:19Z","updated_at":"2016-09-08T09:37:19Z","body":"Fixed the `guard-for-in` warning. Simply check within the for-in loop for the value `k`:\r\n\r\n```\r\n...\r\nfor (var k in value) {\r\n  if(k) { // fixes guard-for-in warning from ESLint\r\n    var v = value[k]\r\n    if (t.form.File.is(v)) {\r\n      fd.append(k, v, v.name)\r\n    } else {\r\n      fd.append(k, v)\r\n    }\r\n  }\r\n}\r\n...\r\n```"}}
{"actor":{"display_login":"sandervanhooft"}}