{"action":"created","issue":{"url":"https://api.github.com/repos/nathanvda/cocoon/issues/346","repository_url":"https://api.github.com/repos/nathanvda/cocoon","labels_url":"https://api.github.com/repos/nathanvda/cocoon/issues/346/labels{/name}","comments_url":"https://api.github.com/repos/nathanvda/cocoon/issues/346/comments","events_url":"https://api.github.com/repos/nathanvda/cocoon/issues/346/events","html_url":"https://github.com/nathanvda/cocoon/issues/346","id":137301830,"number":346,"title":"Fields marked for destruction seem to loose _destroy tag upon validation fail","user":{"login":"nwillis78","id":6104334,"avatar_url":"https://avatars.githubusercontent.com/u/6104334?v=3","gravatar_id":"","url":"https://api.github.com/users/nwillis78","html_url":"https://github.com/nwillis78","followers_url":"https://api.github.com/users/nwillis78/followers","following_url":"https://api.github.com/users/nwillis78/following{/other_user}","gists_url":"https://api.github.com/users/nwillis78/gists{/gist_id}","starred_url":"https://api.github.com/users/nwillis78/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nwillis78/subscriptions","organizations_url":"https://api.github.com/users/nwillis78/orgs","repos_url":"https://api.github.com/users/nwillis78/repos","events_url":"https://api.github.com/users/nwillis78/events{/privacy}","received_events_url":"https://api.github.com/users/nwillis78/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-29T16:29:59Z","updated_at":"2016-02-29T17:17:51Z","closed_at":null,"body":"I have noticed a bug with my project (in this project a question has answers and I am using cocoon to add answers to a question on the same page. A question is validated to make sure it has at least one answer).\r\n\r\nSay I have a question, with an answer \"Option A\", and I remove the answer and press submit then validation fails because option A is marked for destruction as it should be. If I then press submit again the question is saved with Option A as it's answer. It seems that the answer field is no longer marked for destruction after the first time submit is pressed.\r\n\r\nIn my form\r\n```\r\n<table class=\"table\">\r\n\t\t\t<thead>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<th>Answer</th>\r\n\t\t\t\t\t<th>isCorrect</th>\r\n\t\t\t\t</tr>\r\n\t\t\t</thead>\r\n\t\t\t<tbody id=\"answer_table\">\r\n\t\t\t\t<%= f.fields_for :answers do |answer| %>\r\n\t\t\t\t\t<% if !answer.object.marked_for_destruction? %>\r\n\t\t\t\t\t\t\t<%= render 'answer_fields', f: answer %>\r\n\t\t\t\t\t<% end %>\r\n\t\t\t\t\t\t\r\n\t\t\t\t<% end %>\r\n\t\t\t</tbody>\r\n\t\t</table>\r\n```\r\n\r\nIn my _answers_fields\r\n\r\n```\r\n<tr class = \"table_row\" >\r\n\r\n<div class=\"nested-fields\" >\r\n\t\r\n\t\t<td class=\"col-sm-10\">\t\r\n\t\t\t<div class = \"field\">\r\n\t\t\t\t<%= f.text_field :answerString, class: \"text_field_in_grid\"%>\r\n\t\t\t</div>\r\n\t\t</td>\r\n\t\t<td class=\"col-sm-1\">\r\n\t\t\t<div class = \"field\">\r\n\t\t\t\t<%= f.check_box :isCorrect %>\r\n\t\t\t</div>\r\n\t\t</td>\r\n\t\t<td class=\"col-sm-1\">\r\n\t\t\t<div id=\"button_text\">\r\n\t\t\t\t<button type=\"button\" class=\"btn btn-danger\">\r\n\t\t\t\t<%= link_to_remove_association \"Remove answer\", f, {wrapper_class: 'table_row'} %>\r\n\t\t\t\t</button>\r\n\t\t\t</div>\r\n\t\t</td>\r\n\t\r\n</div></tr>\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nathanvda/cocoon/issues/comments/190296871","html_url":"https://github.com/nathanvda/cocoon/issues/346#issuecomment-190296871","issue_url":"https://api.github.com/repos/nathanvda/cocoon/issues/346","id":190296871,"user":{"login":"nathanvda","id":34460,"avatar_url":"https://avatars.githubusercontent.com/u/34460?v=3","gravatar_id":"","url":"https://api.github.com/users/nathanvda","html_url":"https://github.com/nathanvda","followers_url":"https://api.github.com/users/nathanvda/followers","following_url":"https://api.github.com/users/nathanvda/following{/other_user}","gists_url":"https://api.github.com/users/nathanvda/gists{/gist_id}","starred_url":"https://api.github.com/users/nathanvda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathanvda/subscriptions","organizations_url":"https://api.github.com/users/nathanvda/orgs","repos_url":"https://api.github.com/users/nathanvda/repos","events_url":"https://api.github.com/users/nathanvda/events{/privacy}","received_events_url":"https://api.github.com/users/nathanvda/received_events","type":"User","site_admin":false},"created_at":"2016-02-29T17:17:51Z","updated_at":"2016-02-29T17:17:51Z","body":"Weird this should work. It relies on the presence of the `_destroy` flag, if marked for destruction it will get a special class `destroyed` and the js will even hide deleted fields (note: there was a turbolinks error which is only recently fixed).\r\n\r\nI think the problem is in your `marked_for_destruction?` check: this will make sure it is not shown in the form, and thus not saved, and thus it will not be changed (and still exist imho)."}}