@@ -99,13 +99,43 @@ $(function() {
9999 } ) ;
100100 }
101101
102+ // TomSelect for meeting organisers (multi-select)
103+ if ( $ ( '#meeting_organisers' ) . length ) {
104+ new TomSelect ( '#meeting_organisers' , {
105+ plugins : [ 'remove_button' ] ,
106+ placeholder : 'Type to search members...' ,
107+ valueField : 'id' ,
108+ labelField : 'full_name' ,
109+ searchField : [ 'full_name' , 'email' ] ,
110+ create : false ,
111+ loadThrottle : 300 ,
112+ shouldLoad : function ( query ) {
113+ return query . length >= 3 ;
114+ } ,
115+ load : function ( query , callback ) {
116+ fetch ( '/admin/members/search?q=' + encodeURIComponent ( query ) )
117+ . then ( response => response . json ( ) )
118+ . then ( json => callback ( json ) )
119+ . catch ( ( ) => callback ( ) ) ;
120+ } ,
121+ render : {
122+ option : function ( item , escape ) {
123+ return '<div>' + escape ( item . full_name ) + ' <small class="text-muted">' + escape ( item . email ) + '</small></div>' ;
124+ } ,
125+ no_results : function ( data , escape ) {
126+ return '<div class="no-results">No members found</div>' ;
127+ }
128+ }
129+ } ) ;
130+ }
131+
102132 // Chosen for all other selects (exclude TomSelect fields)
103133 // Chosen hides inputs and selects, which becomes problematic when they are
104134 // required: browser validation doesn't get shown to the user.
105135 // This fix places "the original input behind the Chosen input, matching the
106136 // height and width so that the warning appears in the correct position."
107137 // https://github.com/harvesthq/chosen/issues/515#issuecomment-474588057
108- $ ( 'select' ) . not ( '#member_lookup_id, #meeting_invitations_member' ) . on ( 'chosen:ready' , function ( ) {
138+ $ ( 'select' ) . not ( '#member_lookup_id, #meeting_invitations_member, #meeting_organisers ' ) . on ( 'chosen:ready' , function ( ) {
109139 var height = $ ( this ) . next ( '.chosen-container' ) . height ( ) ;
110140 var width = $ ( this ) . next ( '.chosen-container' ) . width ( ) ;
111141
@@ -117,7 +147,7 @@ $(function() {
117147 } ) . show ( ) ;
118148 } ) ;
119149
120- $ ( 'select' ) . not ( '#member_lookup_id, #meeting_invitations_member' ) . chosen ( {
150+ $ ( 'select' ) . not ( '#member_lookup_id, #meeting_invitations_member, #meeting_organisers ' ) . chosen ( {
121151 allow_single_deselect : true ,
122152 no_results_text : 'No results matched'
123153 } ) ;
0 commit comments