From 0fb0727091be4a53550213e1fda99deb1c1a7443 Mon Sep 17 00:00:00 2001 From: Fatih Alp Date: Sun, 19 Apr 2020 15:12:21 +0300 Subject: [PATCH] select2 is not a function error fix --- .../resources/js/vendor/visiosoft.js | 63 ++++++++++--------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/addons/default/visiosoft/defaultadmin-theme/resources/js/vendor/visiosoft.js b/addons/default/visiosoft/defaultadmin-theme/resources/js/vendor/visiosoft.js index 60e13e278..17356fdf1 100644 --- a/addons/default/visiosoft/defaultadmin-theme/resources/js/vendor/visiosoft.js +++ b/addons/default/visiosoft/defaultadmin-theme/resources/js/vendor/visiosoft.js @@ -1,33 +1,36 @@ $( document ).ready(function() { - $("select[name='parent_category']").select2({ - ajax: { - url: window.location.origin + "/keySearch", - type: "GET", - data: function (params) { - return { - q: params.term // search term - }; + if ($("select[name='parent_category']").length ) { + $("select[name='parent_category']").select2({ + ajax: { + url: window.location.origin + "/keySearch", + type: "GET", + data: function (params) { + return { + q: params.term // search term + }; + }, + processResults: function (data) { + return { + results: $.map(data.category, function (item) { + return { + text: item.parents, + id: item.id + } + }) + }; + }, + cache: true }, - processResults: function (data) { - return { - results: $.map(data.category, function (item) { - return { - text: item.parents, - id: item.id - } - }) - }; - }, - cache: true - }, - allowClear: true, - theme: "classic", - placeholder:"All" , - minimumInputLength: 3 - }); + allowClear: true, + theme: "classic", + placeholder:"All" , + minimumInputLength: 3 + }); - $("select[name='parent_category']").on('select2:select', function (e) { - var data = e.params.data; - $("input[name='category_name']").val(data.text); - }); -}); \ No newline at end of file + $("select[name='parent_category']").on('select2:select', function (e) { + var data = e.params.data; + $("input[name='category_name']").val(data.text); + }); + } + +});