{"action":"created","issue":{"url":"https://api.github.com/repos/uploadcare/uploadcare-widget/issues/176","labels_url":"https://api.github.com/repos/uploadcare/uploadcare-widget/issues/176/labels{/name}","comments_url":"https://api.github.com/repos/uploadcare/uploadcare-widget/issues/176/comments","events_url":"https://api.github.com/repos/uploadcare/uploadcare-widget/issues/176/events","html_url":"https://github.com/uploadcare/uploadcare-widget/pull/176","id":40823286,"number":176,"title":"Robust input value","user":{"login":"homm","id":128982,"avatar_url":"https://avatars.githubusercontent.com/u/128982?v=3","gravatar_id":"","url":"https://api.github.com/users/homm","html_url":"https://github.com/homm","followers_url":"https://api.github.com/users/homm/followers","following_url":"https://api.github.com/users/homm/following{/other_user}","gists_url":"https://api.github.com/users/homm/gists{/gist_id}","starred_url":"https://api.github.com/users/homm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/homm/subscriptions","organizations_url":"https://api.github.com/users/homm/orgs","repos_url":"https://api.github.com/users/homm/repos","events_url":"https://api.github.com/users/homm/events{/privacy}","received_events_url":"https://api.github.com/users/homm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-08-21T16:36:00Z","updated_at":"2015-02-12T18:30:54Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/uploadcare/uploadcare-widget/pulls/176","html_url":"https://github.com/uploadcare/uploadcare-widget/pull/176","diff_url":"https://github.com/uploadcare/uploadcare-widget/pull/176.diff","patch_url":"https://github.com/uploadcare/uploadcare-widget/pull/176.patch"},"body":"This changes address issue described by @dimier.\r\n\r\nIn the past input's value always reflects current widget value. This pr allows input's value change only in two cases:\r\n1) new object loaded successfully\r\n2) user removes current object by hand (widget is clearable)\r\n\r\nIn case, described by @dimier, when widget has \"bad value\" (malformed uuid or network error was happened) as initial input value, the user see the problem (widget says \"Can’t load info\" or \"Incorrect value\"). She can ignore it and save form without changing file (bad value will be returned to the application) or upload a new file. May be in case of \"clearable\" we should also show \"remove\" button to allow user to remove bad value.\r\n\r\nOther cases:\r\n\r\n* Widget is empty, user chooses a new file and network error happens. Value will be empty, like with old behavior.\r\n\r\n* Widget already has uploaded file, user chooses a new file and network error happens. Old value will be saved in input, widget will show error. User will not be able to see or remove old file from widget. Looks like a issue"},"comment":{"url":"https://api.github.com/repos/uploadcare/uploadcare-widget/issues/comments/74124709","html_url":"https://github.com/uploadcare/uploadcare-widget/pull/176#issuecomment-74124709","issue_url":"https://api.github.com/repos/uploadcare/uploadcare-widget/issues/176","id":74124709,"user":{"login":"homm","id":128982,"avatar_url":"https://avatars.githubusercontent.com/u/128982?v=3","gravatar_id":"","url":"https://api.github.com/users/homm","html_url":"https://github.com/homm","followers_url":"https://api.github.com/users/homm/followers","following_url":"https://api.github.com/users/homm/following{/other_user}","gists_url":"https://api.github.com/users/homm/gists{/gist_id}","starred_url":"https://api.github.com/users/homm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/homm/subscriptions","organizations_url":"https://api.github.com/users/homm/orgs","repos_url":"https://api.github.com/users/homm/repos","events_url":"https://api.github.com/users/homm/events{/privacy}","received_events_url":"https://api.github.com/users/homm/received_events","type":"User","site_admin":false},"created_at":"2015-02-12T18:30:54Z","updated_at":"2015-02-12T18:30:54Z","body":"Эти изменения немного меняют поведение виджета с точки js api и форм.\r\n\r\nС точки зрения js api, раньше как только виджету не удавалось загрузить файл (без разницы: сетевые ошибки, валидаторы), виджет сбрасывал файл, его нельзя было получить через `.value()`. Теперь значение виджета (файл с ошибкой) и вид виджета (показывает ошибку) одинаковы. Т.к. объект файла не теряется, в будущем это также позволит делать ручной ретрай.\r\n\r\nС точки зрения форм: раньше виджет очищал поле сразу же как выбирался другой файл, а новый файл присваивался по окончании загрузки. Теперь значение поля не сбрасывается. Это значит, что если например был загружен файл, а новый файл загрузить не удалось, в поле по прежнему будет старый файл. Мне кажется это более полезным, чем пустое поле. При этом поле нормально сбрасывается если виджет очищен (пользователь нажал remove или вызвано `value(null)`.\r\n\r\nКроме этого добавил `AnyWidget`, потому что сколько можно писать одно и то же:\r\n\r\n```js\r\n    var widget;\r\n    if (input.data('multiple')) {\r\n      widget = uploadcare.MultipleWidget(input);\r\n    } else {\r\n      widget = uploadcare.Widget(input);\r\n    }\r\n```"}}