From 256ea158c5b2a7e0210bb3a978846c2da5aee8d5 Mon Sep 17 00:00:00 2001 From: Pawan Kumar Date: Fri, 15 Sep 2023 16:15:45 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20new(select):=20select=20smartsearch?= =?UTF-8?q?=20custom=20url=20option=20added.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/shared-ui/select2.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/assets/js/shared-ui/select2.js b/assets/js/shared-ui/select2.js index 2e989f8e..d9597013 100644 --- a/assets/js/shared-ui/select2.js +++ b/assets/js/shared-ui/select2.js @@ -156,6 +156,27 @@ }; + SUI.select.formatSearchOptions = ( data, container ) => { + + let markup; + + const label = SUI.select.escapeJS( data.text ); + const url = $( data.element ).attr( 'data-url' ); + + if ( ! data.id ) { + return label; // optgroup. + } + + if ( 'undefined' !== typeof url ) { + markup = '' + label + '' + url + ' '; + } else { + markup = label; + } + + return markup; + + }; + SUI.select.formatVarsSelection = ( data, container ) => { let markup; @@ -235,6 +256,10 @@ dropdownParent: selectParent, minimumInputLength: 2, maximumSelectionLength: 1, + templateResult: SUI.select.formatSearchOptions, + escapeMarkup: function( markup ) { + return markup; + }, dropdownCssClass: isSmall }); };