{"action":"closed","issue":{"url":"https://api.github.com/repos/ant-design/ant-design/issues/7293","repository_url":"https://api.github.com/repos/ant-design/ant-design","labels_url":"https://api.github.com/repos/ant-design/ant-design/issues/7293/labels{/name}","comments_url":"https://api.github.com/repos/ant-design/ant-design/issues/7293/comments","events_url":"https://api.github.com/repos/ant-design/ant-design/issues/7293/events","html_url":"https://github.com/ant-design/ant-design/issues/7293","id":252149026,"number":7293,"title":"form has ability to set field isTouched.  表单能够设置某个表单项的 isTouched 的值","user":{"login":"pannz","id":5423451,"avatar_url":"https://avatars2.githubusercontent.com/u/5423451?v=4","gravatar_id":"","url":"https://api.github.com/users/pannz","html_url":"https://github.com/pannz","followers_url":"https://api.github.com/users/pannz/followers","following_url":"https://api.github.com/users/pannz/following{/other_user}","gists_url":"https://api.github.com/users/pannz/gists{/gist_id}","starred_url":"https://api.github.com/users/pannz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pannz/subscriptions","organizations_url":"https://api.github.com/users/pannz/orgs","repos_url":"https://api.github.com/users/pannz/repos","events_url":"https://api.github.com/users/pannz/events{/privacy}","received_events_url":"https://api.github.com/users/pannz/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"benjycui","id":3580607,"avatar_url":"https://avatars0.githubusercontent.com/u/3580607?v=4","gravatar_id":"","url":"https://api.github.com/users/benjycui","html_url":"https://github.com/benjycui","followers_url":"https://api.github.com/users/benjycui/followers","following_url":"https://api.github.com/users/benjycui/following{/other_user}","gists_url":"https://api.github.com/users/benjycui/gists{/gist_id}","starred_url":"https://api.github.com/users/benjycui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjycui/subscriptions","organizations_url":"https://api.github.com/users/benjycui/orgs","repos_url":"https://api.github.com/users/benjycui/repos","events_url":"https://api.github.com/users/benjycui/events{/privacy}","received_events_url":"https://api.github.com/users/benjycui/received_events","type":"User","site_admin":false},"assignees":[{"login":"benjycui","id":3580607,"avatar_url":"https://avatars0.githubusercontent.com/u/3580607?v=4","gravatar_id":"","url":"https://api.github.com/users/benjycui","html_url":"https://github.com/benjycui","followers_url":"https://api.github.com/users/benjycui/followers","following_url":"https://api.github.com/users/benjycui/following{/other_user}","gists_url":"https://api.github.com/users/benjycui/gists{/gist_id}","starred_url":"https://api.github.com/users/benjycui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjycui/subscriptions","organizations_url":"https://api.github.com/users/benjycui/orgs","repos_url":"https://api.github.com/users/benjycui/repos","events_url":"https://api.github.com/users/benjycui/events{/privacy}","received_events_url":"https://api.github.com/users/benjycui/received_events","type":"User","site_admin":false}],"milestone":null,"comments":4,"created_at":"2017-08-23T03:25:53Z","updated_at":"2017-09-04T07:44:11Z","closed_at":"2017-09-04T07:44:11Z","author_association":"NONE","body":"### What problem does this feature solve?\r\nen description:\r\nI encountered this problem by this:\r\nthere is a form that contains many form item, inside there is a upload component item.  And the form is wrapped by From.create(). my problem happened on the upload item, here is the code:\r\n\r\n```\r\n<FormItem {...formItemProps}>\r\n    {\r\n         getFieldDecorator( 'url',  {...})(\r\n               <Input style={{display: 'none'}}/>\r\n         )\r\n    }\r\n    <Dragger {..draggerProps}>...</Dragger> \r\n</FormItem>\r\n```\r\n\r\nI use getFieldDecorator to decorate a hidden input, and put the upload outside decorator function.\r\nthe upload onChange event handler get the uploaded image url and set to decorated value `url` by `form.setFieldValue({ url : 'xxx'})`. ( I am not putting upload component inside the field decorator because `url` value would be a file object if it is inside the field decorator, and I think use hidden input is better)\r\nAnd by this way the `url` value would be correct set and validate.  When we try to update the form by change some items, we usually call `form.isFieldsTouched()` method before confirm submit to check if the form is really changed, if return false, we think there is no update. And the problem is there, when I only change the upload item (I only want to update the uploaded image) then submit my change, the `form.isFieldsTouched()` says false. \r\nIn my comprehension, the `url` is decorated, in my case it was set by upload onChange function, so  the decorator can't detect this ? \r\nso, there should be another API that has ability to directly set field touched status?\r\nor the existence API some how can resolve this case?\r\n\r\n---\r\n\r\n我是这么遇到问题的，需求是表单里一个有上传图片的表单项，然后写的时候是用From.create() 包装的 from，对上传表单项我处理的方法是 \r\n\r\n```\r\n<FormItem {...formItemProps}>\r\n    {\r\n         getFieldDecorator( 'url',  {...})(\r\n               <Input style={{display: 'none'}}/>\r\n         )\r\n    }\r\n    <Dragger {...draggerProps}>...</Dragger> \r\n</FormItem>\r\n```\r\n\r\n我是用 decorator 装饰一个隐藏的 input，把上传组件置于 decorator 外，用onChange 事件处理把上传的 url 取到后，通过 from.setFieldValue({url : 'xxx'}) 设置表单项的值（之所以这样处理是因为如果把上传组件放在装饰内部，url的value会是一个 file object，我觉得用上面的方式处理比较清晰）\r\n这样处理后值是可以被正确set，validate 的时候也能正确得到并验证，但是，如果这个有多个表单项的表单仅仅只更改了这个上传（比如在这个表单仅仅更新上传的图片这样的操作），在保存的时候在判断 isFieldsTouched 来做只有修改才更新的判断，这个isFieldsTouched 返回 false，表单会认为没有修改。\r\n我理解是 url 值是装饰过的，这里是通过其他的函数直接设置 url 的值，decorator 无法检测到 url 值的变化？\r\n所以，是否应该存在一个接口，可以改变某个表单项的 isTouched 的值。\r\n或者 form 现有的 api 其实能够完成的功能？\r\n\r\n\r\n### What does the proposed API look like?\r\nsetFiledTouched: Function(fieldName, boolean)\r\n// or setFieldIsTouched\r\n\r\n<!-- generated by ant-design-issue-helper. DO NOT REMOVE -->"}}
{"actor":{"display_login":"benjycui"}}