11import { InputItem } from "./base" ;
2- import { deep_copy , make_set } from "../../utils"
3- import { config } from "../../state" ;
2+ import { deep_copy , is_mobile , make_set } from "../../utils"
43
54const options_tpl = `
65{{#options}}
@@ -24,8 +23,13 @@ $.fn.selectpicker.Constructor.BootstrapVersion = '4';
2423export class Select extends InputItem {
2524 static accept_input_types : string [ ] = [ "select" ] ;
2625
26+ use_bootstrap_select : boolean = false ;
27+
2728 constructor ( spec : any , task_id : string , on_input_event : ( event_name : string , input_item : InputItem ) => void ) {
2829 super ( spec , task_id , on_input_event ) ;
30+ if ( spec . native === false || ( spec . native === undefined && spec . multiple && ! is_mobile ( ) ) ) {
31+ this . use_bootstrap_select = true ;
32+ }
2933 }
3034
3135 create_element ( ) : JQuery {
@@ -37,7 +41,7 @@ export class Select extends InputItem {
3741 this . element = $ ( html ) ;
3842 this . setup_select_options ( this . element , spec . options ) ;
3943
40- if ( ! config . disableSelectPicker ) {
44+ if ( this . use_bootstrap_select ) {
4145 // @ts -ignore
4246 this . element . find ( 'select' ) . selectpicker ( ) ;
4347 }
@@ -71,7 +75,7 @@ export class Select extends InputItem {
7175 input_elem . attr ( key , this . spec [ key ] ) ;
7276 }
7377
74- if ( ! config . disableSelectPicker ) {
78+ if ( this . use_bootstrap_select ) {
7579 // @ts -ignore
7680 input_elem . selectpicker ( 'refresh' ) ;
7781 }
@@ -99,7 +103,7 @@ export class Select extends InputItem {
99103 $ ( this ) . prop ( 'selected' , true ) ;
100104 }
101105 } ) ;
102- if ( ! config . disableSelectPicker ) {
106+ if ( this . use_bootstrap_select ) {
103107 // @ts -ignore
104108 this . element . find ( 'select' ) . selectpicker ( 'render' ) ;
105109 }
@@ -111,7 +115,7 @@ export class Select extends InputItem {
111115
112116 on_reset ( e : any ) {
113117 // need to wait some time to get the select element be reset, and then update `selectpicker`
114- if ( ! config . disableSelectPicker )
118+ if ( this . use_bootstrap_select )
115119 setTimeout ( ( ) => {
116120 // @ts -ignore
117121 this . element . find ( 'select' ) . selectpicker ( 'render' ) ;
0 commit comments