@@ -268,19 +268,6 @@ def _input_select_impl(
268268 if options is None :
269269 options = {}
270270
271- if remove_button is None :
272- remove_button = multiple
273-
274- # Translate remove_button into default selectize plugins
275- # N.B. remove_button is primarily for multiple=True and clear_button is for
276- # multiple=False, but both can also be useful in the multiple=True case (i.e., clear
277- # _all_ selected items)
278- default_plugins = None
279- if remove_button == "both" :
280- default_plugins = json .dumps (["remove_button" , "clear_button" ])
281- elif remove_button :
282- default_plugins = json .dumps (["remove_button" if multiple else "clear_button" ])
283-
284271 choices_tags = _render_choices (choices_ , selected )
285272
286273 selectize_config = None
@@ -293,7 +280,7 @@ def _input_select_impl(
293280 # Which option values should be interpreted as JS?
294281 data_eval = json .dumps (extract_js_keys (options )),
295282 # Supply and retain these plugins across updates (on the client)
296- data_default_plugins = default_plugins ,
283+ data_default_plugins = _get_default_plugins ( remove_button , multiple ) ,
297284 )
298285
299286 return div (
@@ -323,17 +310,27 @@ def _normalize_choices(x: SelectChoicesArg) -> _SelectChoices:
323310 return x
324311
325312
326- def _contains_html (x : _SelectChoices ) -> bool :
327- for v in x .values ():
328- if isinstance (v , Mapping ):
329- # Check the `_Choices` values of `_OptGrpChoices`
330- for vv in v .values ():
331- if not isinstance (vv , str ):
332- return True
333- else :
334- if not isinstance (v , str ):
335- return True
336- return False
313+ # Translate remove_button into default selectize plugins
314+ # N.B. remove_button is primarily for multiple=True and clear_button is for
315+ # multiple=False, but both can also be useful in the multiple=True case (i.e., clear
316+ # _all_ selected items)
317+ def _get_default_plugins (
318+ remove_button : Optional [Literal [True , False , "both" ]],
319+ multiple : bool ,
320+ ) -> Optional [str ]:
321+ if remove_button is None :
322+ remove_button = multiple
323+
324+ if remove_button is False :
325+ return None
326+
327+ if remove_button is True :
328+ return json .dumps (["remove_button" if multiple else "clear_button" ])
329+
330+ if remove_button == "both" :
331+ return json .dumps (["remove_button" , "clear_button" ])
332+
333+ raise ValueError (f"Invalid value for `remove_button`: { remove_button } " )
337334
338335
339336def _render_choices (
0 commit comments