From e93b3c7aa5e9d5884745f051a0808f519f3854df Mon Sep 17 00:00:00 2001
From: Marco Patron <marco.patron@bazzmann.it>
Date: Wed, 10 Jun 2015 16:21:21 +0200
Subject: [PATCH] Add a link to remove an item

change html selector and change validation
---
 js/references-dialog.js | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/js/references-dialog.js b/js/references-dialog.js
index 0c23b31..2be62d3 100644
--- a/js/references-dialog.js
+++ b/js/references-dialog.js
@@ -44,6 +44,30 @@
             return false;
           });
         });
+        
+        // Provide a 'remove' button on entityreference fields.
+        $('.field-type-entityreference').each(function(i) {
+          $('.references-dialog-links', this).each(function(i) {
+            if (($('li.first a.edit-dialog', this).length >= 0) && ($('li a.remove-dialog', this).length <= 0)) {
+              $('li.last', this).removeClass('last').parent().append('<li><a href="#" class="remove-dialog">Rimuovi</a></li>');
+              
+              var index = ($('li', this).length - 1).toString(); 
+              $('li', this).last().addClass(index).addClass('last');
+              
+              $('a.remove-dialog', this).click(function() {
+                // Hide this row entirely.
+                $(this).parents('li').hide();
+                
+                
+                var currentID = $(this).parents().find('input.form-autocomplete').attr('id');
+                var emptyInput = $('#' + currentID);
+                $(emptyInput).val('');
+
+                return false;
+              });
+            }
+          });
+        });
       }
     }
   };
-- 
2.3.2 (Apple Git-55)

