File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ ( function ( $ ) {
2+ $ . fn . ajaxSelectBox = function ( options ) {
3+ return this . each ( function ( ) {
4+ var options = Object . assign ( { } , selectOptions ) ;
5+ var select = $ ( this ) ;
6+ if ( select . data ( 'ajaxselect' ) ) {
7+ options = Object . assign ( options , {
8+ tokenSeparators : [ ',' ] ,
9+ ajax : {
10+ url : select . data ( 'ajaxselect' ) ,
11+ delay : 250 ,
12+ dataType : 'json' ,
13+ data : function ( params ) {
14+ return {
15+ q : params . term
16+ } ;
17+ } ,
18+ processResults : function ( data , params ) {
19+ return {
20+ results : data
21+ } ;
22+ }
23+ }
24+ } ) ;
25+ }
26+ if ( select . data ( 'onchange' ) ) {
27+ var currentQuery ;
28+ select . on ( 'select2:open' , function ( ) {
29+ setTimeout ( function ( ) {
30+ if ( currentQuery && currentQuery . length ) {
31+ $ ( '.select2-search input' ) . val ( currentQuery ) . trigger ( 'input' ) ;
32+ } ;
33+ } , 0 ) ;
34+ } ) . on ( 'select2:closing' , function ( ) {
35+ currentQuery = $ ( '.select2-search input' ) . prop ( 'value' ) ;
36+ } ) . on ( 'change' , function ( e ) {
37+ $ . nette . ajax ( {
38+ method : 'GET' ,
39+ url : select . data ( 'onchange' ) ,
40+ data : {
41+ s : $ ( this ) . val ( ) ,
42+ }
43+ } ) ;
44+ } ) ;
45+ }
46+ select . select2 ( options ) ;
47+ select . closest ( 'form' ) . on ( 'reset' , function ( e ) { select . change ( ) ; } ) ;
48+ } ) ;
49+ }
50+ } ) ( jQuery ) ;
You can’t perform that action at this time.
0 commit comments