I am using Select2 control with knockout and I have a special requirement where I need to set the minimumInputLength option of the Select2 control dynamically based on the length of the options in the select2 combobox. For example if I have 100 options, I need to set the minimumInputLength to 2 and if its less than 100, I need to set it to nothing (or 0).
I tried the following options. select2Combobox here is a custombinding I created.
1) Have a ko Computed Property (bound to the minimumInputLength setting) which will return 2 or 0 based on the length of the observableArray that the select2 is bound to. Here TypeAheadMinInputLength is my computed property.
select2Combobox: { select2Options: { width: '100%', minimumInputLength: TypeAheadMinInputLength}, data: TypeaheadData}
2) Bind the minimumInputLength setting with a function call which again returns 2 or 0 based on the length of input array that the function is provided with.
select2Combobox: { select2Options: { width: '100%', minimumInputLength: getTypeAheadMinInputLength(TypeaheadData())}, data: TypeaheadData}
Any suggestions
Thanks.