From 804f4f55210b28c365002a022e13d2894a21b9f7 Mon Sep 17 00:00:00 2001
From: powellzer <spencercpowell@gmail.com>
Date: Thu, 29 Jan 2015 12:05:42 -0500
Subject: [PATCH] Check if select2 input exists before destroy
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Avoiding TypeError of accessing property ‘data’ on an undefined error.
This error occurs when destroying an editable with input type select2
before the select2 has been created.
---
 src/inputs/select2/select2.js | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/inputs/select2/select2.js b/src/inputs/select2/select2.js
index be4c6d5..e4f53cc 100644
--- a/src/inputs/select2/select2.js
+++ b/src/inputs/select2/select2.js
@@ -294,9 +294,11 @@ $(function(){
         },
         
         destroy: function() {
-            if(this.$input.data('select2')) {
-                this.$input.select2('destroy');
-            }
+	        if(this.$input) {
+	            if(this.$input.data('select2')) {
+	                this.$input.select2('destroy');
+	            }
+	        }
         }
         
     });