{"action":"created","comment":{"url":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/comments/53482826","id":53482826,"diff_hunk":"@@ -303,11 +303,35 @@ function xml_form_elements_form_element_tabs_ajax_add(FormElement $element, arra\n     if ($element->controls['#type'] == 'tags') {\n       foreach ($element->children as $child) {\n         $child->default_value = $child->getOriginalDefaultValue();\n-        if (empty($child->default_value)) {\n+\n+        // We should orphan object only if they have no default AND it is not\n+        // the last child.  We must retain one, otherwise we'll get AJAX an\n+        // AJAX error when adding an element after adding another tab.\n+        $no_default = empty($child->default_value);\n+        $is_not_last = count($element->children) > 1;\n+\n+        if ($no_default && $is_not_last) {\n           $child->orphan();\n         }\n       }\n+\n+      // In order to provide functionality identical to when the tab is first\n+      // created, we need to dedeupe based on the first element's default\n+      // value.  Otherwise we can wind up with multiples of the same default\n+      // value.\n+      if (count($element->children > 1)) {\n+        $first = array_shift($element->children);\n+\n+        foreach ($element->children as $child) {\n+          if (strcmp($child->default_value, $first->default_value) == 0) {","path":"elements/xml_form_elements.module","position":25,"original_position":25,"commit_id":"e74d59f1b7ec45234229528347b3549644fe2d58","original_commit_id":"e74d59f1b7ec45234229528347b3549644fe2d58","user":{"login":"adam-vessey","id":607975,"avatar_url":"https://avatars.githubusercontent.com/u/607975?v=3","gravatar_id":"","url":"https://api.github.com/users/adam-vessey","html_url":"https://github.com/adam-vessey","followers_url":"https://api.github.com/users/adam-vessey/followers","following_url":"https://api.github.com/users/adam-vessey/following{/other_user}","gists_url":"https://api.github.com/users/adam-vessey/gists{/gist_id}","starred_url":"https://api.github.com/users/adam-vessey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adam-vessey/subscriptions","organizations_url":"https://api.github.com/users/adam-vessey/orgs","repos_url":"https://api.github.com/users/adam-vessey/repos","events_url":"https://api.github.com/users/adam-vessey/events{/privacy}","received_events_url":"https://api.github.com/users/adam-vessey/received_events","type":"User","site_admin":false},"body":"I'm not sure this is a good assumption, that the same value will not be present twice... Could be legitimate (though likely rare... can't think of an exact use-case off the top of my head). But yeah: Created a form which does it: https://gist.github.com/adam-vessey/935b8180dc9588a86e35\r\n\r\nWhen hitting the button for a new tabpanel, one of the \"default_0\" dealios goes away in the clone.","created_at":"2016-02-19T16:30:42Z","updated_at":"2016-02-19T16:30:42Z","html_url":"https://github.com/Islandora/islandora_xml_forms/pull/214#discussion_r53482826","pull_request_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/214","_links":{"self":{"href":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/comments/53482826"},"html":{"href":"https://github.com/Islandora/islandora_xml_forms/pull/214#discussion_r53482826"},"pull_request":{"href":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/214"}}},"pull_request":{"url":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/214","id":59702435,"html_url":"https://github.com/Islandora/islandora_xml_forms/pull/214","diff_url":"https://github.com/Islandora/islandora_xml_forms/pull/214.diff","patch_url":"https://github.com/Islandora/islandora_xml_forms/pull/214.patch","issue_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/issues/214","number":214,"state":"open","locked":false,"title":"Fixing some funny behaviour from my last commit.","user":{"login":"daniel-dgi","id":2521309,"avatar_url":"https://avatars.githubusercontent.com/u/2521309?v=3","gravatar_id":"","url":"https://api.github.com/users/daniel-dgi","html_url":"https://github.com/daniel-dgi","followers_url":"https://api.github.com/users/daniel-dgi/followers","following_url":"https://api.github.com/users/daniel-dgi/following{/other_user}","gists_url":"https://api.github.com/users/daniel-dgi/gists{/gist_id}","starred_url":"https://api.github.com/users/daniel-dgi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniel-dgi/subscriptions","organizations_url":"https://api.github.com/users/daniel-dgi/orgs","repos_url":"https://api.github.com/users/daniel-dgi/repos","events_url":"https://api.github.com/users/daniel-dgi/events{/privacy}","received_events_url":"https://api.github.com/users/daniel-dgi/received_events","type":"User","site_admin":false},"body":"https://jira.duraspace.org/browse/ISLANDORA-1595\r\n\r\n# What does this Pull Request do?\r\nAdds a check before printing out empty tags to the tags template when situated in a tab and a new tab is added.  But really I'm fixing some broken functionality from #212 that I introduced (not having at least one tag produces an AJAX error).  In other words, I DUN GOOFED, AND NOW I SEE WHY @knjackson30974 WAS PRESERVING AT LEAST ONE ELEMENT.  Please allow me to fix my mess without further embarrassment.  Apologies to both @knjackson30974 and @DiegoPino for any inconvenience.  \r\n\r\n# How should this be tested?\r\nOpen an XML form that has tags within a tab and add some tags. Click to add a new tab and check to see if there are empty tags below the tag field.  Be sure to attempt adding tags to the newly created tab to ensure no AJAX errors are encountered.  \r\n\r\n# Background context:\r\nReported internally a while ago but was still an issue. \r\n\r\n# Additional Notes: \r\n* **Does this change require documentation to be updated?** No\r\n* **Does this change add any new dependencies?** No\r\n* **Does this change require any other modifications to be made to the repository (ie. Regeneration activity, etc.)?** No\r\n* **Could this change impact execution of existing code?** No\r\n\r\n# Additional Information \r\nThis is a simple addition of a check to the Tags template. \r\n\r\n----\r\nDanny Lamb\r\n_Developer_\r\n**[discoverygarden inc.](http://www.discoverygarden.ca) | Managing Digital Content**","created_at":"2016-02-17T20:19:03Z","updated_at":"2016-02-19T16:30:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"17a9815d11cff65563ac35e619b4962d80b8d7d5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/214/commits","review_comments_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/214/comments","review_comment_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/issues/214/comments","statuses_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/statuses/e74d59f1b7ec45234229528347b3549644fe2d58","head":{"label":"daniel-dgi:INT-370","ref":"INT-370","sha":"e74d59f1b7ec45234229528347b3549644fe2d58","user":{"login":"daniel-dgi","id":2521309,"avatar_url":"https://avatars.githubusercontent.com/u/2521309?v=3","gravatar_id":"","url":"https://api.github.com/users/daniel-dgi","html_url":"https://github.com/daniel-dgi","followers_url":"https://api.github.com/users/daniel-dgi/followers","following_url":"https://api.github.com/users/daniel-dgi/following{/other_user}","gists_url":"https://api.github.com/users/daniel-dgi/gists{/gist_id}","starred_url":"https://api.github.com/users/daniel-dgi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniel-dgi/subscriptions","organizations_url":"https://api.github.com/users/daniel-dgi/orgs","repos_url":"https://api.github.com/users/daniel-dgi/repos","events_url":"https://api.github.com/users/daniel-dgi/events{/privacy}","received_events_url":"https://api.github.com/users/daniel-dgi/received_events","type":"User","site_admin":false},"repo":{"id":6445588,"name":"islandora_xml_forms","full_name":"daniel-dgi/islandora_xml_forms","owner":{"login":"daniel-dgi","id":2521309,"avatar_url":"https://avatars.githubusercontent.com/u/2521309?v=3","gravatar_id":"","url":"https://api.github.com/users/daniel-dgi","html_url":"https://github.com/daniel-dgi","followers_url":"https://api.github.com/users/daniel-dgi/followers","following_url":"https://api.github.com/users/daniel-dgi/following{/other_user}","gists_url":"https://api.github.com/users/daniel-dgi/gists{/gist_id}","starred_url":"https://api.github.com/users/daniel-dgi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniel-dgi/subscriptions","organizations_url":"https://api.github.com/users/daniel-dgi/orgs","repos_url":"https://api.github.com/users/daniel-dgi/repos","events_url":"https://api.github.com/users/daniel-dgi/events{/privacy}","received_events_url":"https://api.github.com/users/daniel-dgi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/daniel-dgi/islandora_xml_forms","description":"Build/Store/Render drupal forms that allow for the manipulation of XML files.","fork":true,"url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms","forks_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/forks","keys_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/teams","hooks_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/hooks","issue_events_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/issues/events{/number}","events_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/events","assignees_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/assignees{/user}","branches_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/branches{/branch}","tags_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/tags","blobs_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/git/refs{/sha}","trees_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/statuses/{sha}","languages_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/languages","stargazers_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/stargazers","contributors_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/contributors","subscribers_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/subscribers","subscription_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/subscription","commits_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/commits{/sha}","git_commits_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/git/commits{/sha}","comments_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/comments{/number}","issue_comment_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/issues/comments{/number}","contents_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/contents/{+path}","compare_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/merges","archive_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/downloads","issues_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/issues{/number}","pulls_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/pulls{/number}","milestones_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/milestones{/number}","notifications_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/labels{/name}","releases_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/releases{/id}","deployments_url":"https://api.github.com/repos/daniel-dgi/islandora_xml_forms/deployments","created_at":"2012-10-29T18:38:39Z","updated_at":"2014-02-27T13:57:41Z","pushed_at":"2016-02-17T20:07:38Z","git_url":"git://github.com/daniel-dgi/islandora_xml_forms.git","ssh_url":"git@github.com:daniel-dgi/islandora_xml_forms.git","clone_url":"https://github.com/daniel-dgi/islandora_xml_forms.git","svn_url":"https://github.com/daniel-dgi/islandora_xml_forms","homepage":"","size":33220,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"6.x"}},"base":{"label":"Islandora:7.x","ref":"7.x","sha":"085ef6526b7a47c8194bdbea3e64b5ddef71f269","user":{"login":"Islandora","id":494054,"avatar_url":"https://avatars.githubusercontent.com/u/494054?v=3","gravatar_id":"","url":"https://api.github.com/users/Islandora","html_url":"https://github.com/Islandora","followers_url":"https://api.github.com/users/Islandora/followers","following_url":"https://api.github.com/users/Islandora/following{/other_user}","gists_url":"https://api.github.com/users/Islandora/gists{/gist_id}","starred_url":"https://api.github.com/users/Islandora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Islandora/subscriptions","organizations_url":"https://api.github.com/users/Islandora/orgs","repos_url":"https://api.github.com/users/Islandora/repos","events_url":"https://api.github.com/users/Islandora/events{/privacy}","received_events_url":"https://api.github.com/users/Islandora/received_events","type":"Organization","site_admin":false},"repo":{"id":2048843,"name":"islandora_xml_forms","full_name":"Islandora/islandora_xml_forms","owner":{"login":"Islandora","id":494054,"avatar_url":"https://avatars.githubusercontent.com/u/494054?v=3","gravatar_id":"","url":"https://api.github.com/users/Islandora","html_url":"https://github.com/Islandora","followers_url":"https://api.github.com/users/Islandora/followers","following_url":"https://api.github.com/users/Islandora/following{/other_user}","gists_url":"https://api.github.com/users/Islandora/gists{/gist_id}","starred_url":"https://api.github.com/users/Islandora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Islandora/subscriptions","organizations_url":"https://api.github.com/users/Islandora/orgs","repos_url":"https://api.github.com/users/Islandora/repos","events_url":"https://api.github.com/users/Islandora/events{/privacy}","received_events_url":"https://api.github.com/users/Islandora/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Islandora/islandora_xml_forms","description":"Build/Store/Render drupal forms that allow for the manipulation of XML files.","fork":false,"url":"https://api.github.com/repos/Islandora/islandora_xml_forms","forks_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/forks","keys_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/teams","hooks_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/hooks","issue_events_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/issues/events{/number}","events_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/events","assignees_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/assignees{/user}","branches_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/branches{/branch}","tags_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/tags","blobs_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/git/refs{/sha}","trees_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/statuses/{sha}","languages_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/languages","stargazers_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/stargazers","contributors_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/contributors","subscribers_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/subscribers","subscription_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/subscription","commits_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/commits{/sha}","git_commits_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/git/commits{/sha}","comments_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/comments{/number}","issue_comment_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/issues/comments{/number}","contents_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/contents/{+path}","compare_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/merges","archive_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/downloads","issues_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/issues{/number}","pulls_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls{/number}","milestones_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/milestones{/number}","notifications_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/labels{/name}","releases_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/releases{/id}","deployments_url":"https://api.github.com/repos/Islandora/islandora_xml_forms/deployments","created_at":"2011-07-14T18:13:03Z","updated_at":"2015-06-24T15:23:22Z","pushed_at":"2016-02-18T22:05:01Z","git_url":"git://github.com/Islandora/islandora_xml_forms.git","ssh_url":"git@github.com:Islandora/islandora_xml_forms.git","clone_url":"https://github.com/Islandora/islandora_xml_forms.git","svn_url":"https://github.com/Islandora/islandora_xml_forms","homepage":"","size":33346,"stargazers_count":21,"watchers_count":21,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":47,"mirror_url":null,"open_issues_count":2,"forks":47,"open_issues":2,"watchers":21,"default_branch":"7.x"}},"_links":{"self":{"href":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/214"},"html":{"href":"https://github.com/Islandora/islandora_xml_forms/pull/214"},"issue":{"href":"https://api.github.com/repos/Islandora/islandora_xml_forms/issues/214"},"comments":{"href":"https://api.github.com/repos/Islandora/islandora_xml_forms/issues/214/comments"},"review_comments":{"href":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/214/comments"},"review_comment":{"href":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Islandora/islandora_xml_forms/pulls/214/commits"},"statuses":{"href":"https://api.github.com/repos/Islandora/islandora_xml_forms/statuses/e74d59f1b7ec45234229528347b3549644fe2d58"}}}}