Combined select
Two select components that work together to ensure only one can be selected at a time.
CombinedSelectOptionsLoaderTypes = CombinedSelectOptionsLoaderProtocol | Callable[[], CombinedSelectOptionsLoaderProtocol]
module-attribute
CombinedSelectComponent
Bases: ComponentState
opts_a = []
class-attribute
instance-attribute
opts_b = []
class-attribute
instance-attribute
selected_a = ''
class-attribute
instance-attribute
selected_b = ''
class-attribute
instance-attribute
create_select_a(label, initial_values, id_=None)
classmethod
Create the first select component.
create_select_b(label, initial_values, id_=None)
classmethod
Create the second select component.
get_component(*args, **kwargs)
abstractmethod
classmethod
Override to create the component with desired layout.
Note: The signature can be changed. This is args, *kwargs to allow for flexibility in subclassing.
get_values()
Get the current selection state.
handle_change_a(value)
async
Handle changing only the first select component.
handle_change_b(value)
async
Handle changing only the second select component.
handle_load()
async
If a ._loader is set, execute that to load the next set of options.
This is optional. It is likely that a more general rx.State should pass in the options and control the loading behaviour itself.
register_loader(loader)
classmethod
Register a loader that the .handle_load method will use.
register_on_change_listener(listener)
classmethod
Register a listener that will be called when the selection changes.
set_initial_values(initial_values)
classmethod
Use initial values to set up the component.
Note: Should only be called on a specific instance of the class
select = CombinedSelectComponent.create()
select.State.set_initial_values(...)
set_values(state)
Update the selection state with an instance of CombinedSelectValues.
update_selection_for_new_options(opts_a, opts_b)
Update the selection component when options have changed.
Note: This should be called from external state if external state managing options.
CombinedSelectComponentProtocol
Bases: Protocol
The public interface for a combined select component.
Note: There are a lot of internals to making it work that generally shouldn't be used directly.
get_values()
abstractmethod
Get the current selection state.
handle_load()
async
Handle loading options via the registered loader.
Trigger this event handler to load new options (if loader registered).
register_loader(loader)
classmethod
Register a loader that the .handle_load method will use.
Note: Either do this, or pass in options via external state attributes. If options are passed in as external state attributes then validation of selections on options change will be disabled.
register_on_change_listener(listener)
classmethod
Register a listener that will be called when the selection changes.
set_values(state)
Set the current selection state.
CombinedSelectInitialValues
Bases: BaseModel
model_config = ConfigDict(arbitrary_types_allowed=True)
class-attribute
instance-attribute
opts_a
instance-attribute
opts_b
instance-attribute
selected_a = None
class-attribute
instance-attribute
selected_b = None
class-attribute
instance-attribute
validate_selections()
CombinedSelectOptions
dataclass
opts_a
instance-attribute
opts_b
instance-attribute
__init__(opts_a, opts_b)
CombinedSelectValues
Bases: BaseModel