Skip to content

Update SelectionList based on Input submission #5621

Answered by ddkasa
AndyDralle asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @AndyDralle,

Something like this will work after the user presses the enter key:

from textual.app import App, ComposeResult
from textual.widgets import SelectionList, Input


class SandboxApp(App[None]):
    def compose(self) -> ComposeResult:
        yield Input()
        yield SelectionList(
            ("fizz", "fizz"),
            ("buzz", "buzz"),
            ("foo", "foo"),
        )

    def on_input_submitted(self, message: Input.Submitted) -> None:
        self.query_one(SelectionList).select(message.value)
        message.input.clear()


if __name__ == "__main__":
    SandboxApp().run()

Could validate the selection more or remove the clear method if the previous value is requ…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AndyDralle
Comment options

Answer selected by AndyDralle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants