From 25c89d11f9ecb3f0ec37c11ebc09c3d30c0e25f6 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 2 Mar 2017 18:09:14 +0200 Subject: [PATCH] Support creating inline vendors and categories --- .../views/partials/entity_combobox.blade.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 resources/views/partials/entity_combobox.blade.php diff --git a/resources/views/partials/entity_combobox.blade.php b/resources/views/partials/entity_combobox.blade.php new file mode 100644 index 000000000000..67cd39738844 --- /dev/null +++ b/resources/views/partials/entity_combobox.blade.php @@ -0,0 +1,28 @@ +var {{ $entityType }}Name = ''; + +${{ $entityType }}Select.combobox({ + highlighter: function (item) { + if (item.indexOf("{{ trans("texts.create_{$entityType}") }}") == 0) { + {{ $entityType }}Name = this.query; + return "{{ trans("texts.create_{$entityType}") }}: " + this.query; + } else { + var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&'); + return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) { + return '' + match + ''; + }) + } + }, + template: '
', + matcher: function (item) { + // if the user has entered a value show the 'Create ...' option + if (item.indexOf("{{ trans("texts.create_{$entityType}") }}") == 0) { + return this.query.length; + } + return ~item.toLowerCase().indexOf(this.query.toLowerCase()); + } +}).on('change', function(e) { + var {{ $entityType }}Id = $('input[name={{ $entityType }}_id]').val(); + if ({{ $entityType }}Id == '-1') { + $('#{{ $entityType }}_name').val({{ $entityType }}Name); + } +});