|
@@ -17,6 +17,7 @@ class Select(ChoiceElement, DisableableElement, component='select.js'):
|
|
with_input: bool = False,
|
|
with_input: bool = False,
|
|
multiple: bool = False,
|
|
multiple: bool = False,
|
|
clearable: bool = False,
|
|
clearable: bool = False,
|
|
|
|
+ add_new_unique_values: bool = False,
|
|
) -> None:
|
|
) -> None:
|
|
"""Dropdown Selection
|
|
"""Dropdown Selection
|
|
|
|
|
|
@@ -31,6 +32,7 @@ class Select(ChoiceElement, DisableableElement, component='select.js'):
|
|
:param with_input: whether to show an input field to filter the options
|
|
:param with_input: whether to show an input field to filter the options
|
|
:param multiple: whether to allow multiple selections
|
|
:param multiple: whether to allow multiple selections
|
|
:param clearable: whether to add a button to clear the selection
|
|
:param clearable: whether to add a button to clear the selection
|
|
|
|
+ :param add_new_unique_values: allow to add new unique values, equivalent to `new-value-mode="add-unique"`. Is only applied if `with_input == True`.
|
|
"""
|
|
"""
|
|
self.multiple = multiple
|
|
self.multiple = multiple
|
|
if multiple:
|
|
if multiple:
|
|
@@ -47,6 +49,8 @@ class Select(ChoiceElement, DisableableElement, component='select.js'):
|
|
self._props['hide-selected'] = not multiple
|
|
self._props['hide-selected'] = not multiple
|
|
self._props['fill-input'] = True
|
|
self._props['fill-input'] = True
|
|
self._props['input-debounce'] = 0
|
|
self._props['input-debounce'] = 0
|
|
|
|
+ if add_new_unique_values:
|
|
|
|
+ self._props['new-value-mode'] = 'add-unique'
|
|
self._props['multiple'] = multiple
|
|
self._props['multiple'] = multiple
|
|
self._props['clearable'] = clearable
|
|
self._props['clearable'] = clearable
|
|
|
|
|
|
@@ -63,11 +67,26 @@ class Select(ChoiceElement, DisableableElement, component='select.js'):
|
|
if self.multiple:
|
|
if self.multiple:
|
|
if e.args is None:
|
|
if e.args is None:
|
|
return []
|
|
return []
|
|
- return [self._values[arg['value']] for arg in e.args]
|
|
|
|
|
|
+ else:
|
|
|
|
+ out = []
|
|
|
|
+ for arg in e.args:
|
|
|
|
+ if isinstance(arg, str):
|
|
|
|
+ self.options.append(arg)
|
|
|
|
+ self.update()
|
|
|
|
+ out.append(self._values[len(self.options) - 1])
|
|
|
|
+ else:
|
|
|
|
+ out.append(self._values[arg['value']])
|
|
|
|
+ return out
|
|
else:
|
|
else:
|
|
if e.args is None:
|
|
if e.args is None:
|
|
return None
|
|
return None
|
|
- return self._values[e.args['value']]
|
|
|
|
|
|
+ else:
|
|
|
|
+ if isinstance(e.args, str):
|
|
|
|
+ self.options.append(e.args)
|
|
|
|
+ self.update()
|
|
|
|
+ return self._values[len(self.options) - 1]
|
|
|
|
+ else:
|
|
|
|
+ return self._values[e.args['value']]
|
|
|
|
|
|
def _value_to_model_value(self, value: Any) -> Any:
|
|
def _value_to_model_value(self, value: Any) -> Any:
|
|
# pylint: disable=no-else-return
|
|
# pylint: disable=no-else-return
|