@@ -70,13 +70,42 @@ $(function() {
7070 } ) ;
7171 }
7272
73- // Chosen for all other selects (exclude #member_lookup_id)
73+ // TomSelect for meeting invitation member lookup
74+ if ( $ ( '#meeting_invitations_member' ) . length ) {
75+ new TomSelect ( '#meeting_invitations_member' , {
76+ placeholder : 'Type to search members...' ,
77+ valueField : 'id' ,
78+ labelField : 'full_name' ,
79+ searchField : [ 'full_name' , 'email' ] ,
80+ create : false ,
81+ loadThrottle : 300 ,
82+ shouldLoad : function ( query ) {
83+ return query . length >= 3 ;
84+ } ,
85+ load : function ( query , callback ) {
86+ fetch ( '/admin/members/search?q=' + encodeURIComponent ( query ) )
87+ . then ( response => response . json ( ) )
88+ . then ( json => callback ( json ) )
89+ . catch ( ( ) => callback ( ) ) ;
90+ } ,
91+ render : {
92+ option : function ( item , escape ) {
93+ return '<div>' + escape ( item . full_name ) + ' <small class="text-muted">' + escape ( item . email ) + '</small></div>' ;
94+ } ,
95+ no_results : function ( data , escape ) {
96+ return '<div class="no-results">No members found</div>' ;
97+ }
98+ }
99+ } ) ;
100+ }
101+
102+ // Chosen for all other selects (exclude TomSelect fields)
74103 // Chosen hides inputs and selects, which becomes problematic when they are
75104 // required: browser validation doesn't get shown to the user.
76105 // This fix places "the original input behind the Chosen input, matching the
77106 // height and width so that the warning appears in the correct position."
78107 // https://github.com/harvesthq/chosen/issues/515#issuecomment-474588057
79- $ ( 'select' ) . not ( '#member_lookup_id' ) . on ( 'chosen:ready' , function ( ) {
108+ $ ( 'select' ) . not ( '#member_lookup_id, #meeting_invitations_member ' ) . on ( 'chosen:ready' , function ( ) {
80109 var height = $ ( this ) . next ( '.chosen-container' ) . height ( ) ;
81110 var width = $ ( this ) . next ( '.chosen-container' ) . width ( ) ;
82111
@@ -88,7 +117,7 @@ $(function() {
88117 } ) . show ( ) ;
89118 } ) ;
90119
91- $ ( 'select' ) . not ( '#member_lookup_id' ) . chosen ( {
120+ $ ( 'select' ) . not ( '#member_lookup_id, #meeting_invitations_member ' ) . chosen ( {
92121 allow_single_deselect : true ,
93122 no_results_text : 'No results matched'
94123 } ) ;
0 commit comments