Skip to content

multiple @on decorators in one class not handled #6248

@AlfredoCubitos

Description

@AlfredoCubitos

in the following code only the second @on decorator works as expected.
When I comment out the second @on decorator, the first works as expected.

Is this a bug or can I only use one @on decorator in a class?

class MyClass(ModalScreen)
   
  def compose(self)->ComposeResult:
        yield Grid(
                Label("Add A Playlist Item", id="pl_title"),
                Static(id="pl_image"),
                Label("Name"),
                Input(id="pl_name",validators=[Length(minimum=2,maximum=30)]),
                Label("Category"),
                Input(id="pl_cat"),
                Label("URL"),
                Input(id="pl_uri",validators=[URL()]),
                Static(), #place holder
                Button("Cancel",id="cancel"),
                Button("OK",id="save"),
                id="dialog",
            )

   @on(Input.Submitted,"#pl_name")
    def show_invalid_reasons(self, event: Input.Submitted) -> None:
        if not event.validation_result.is_valid:
            self.input_error = True
            self.notify(str(event.validation_result.failure_descriptions),severity="error", timeout=10)

        else:
            self.input_error = False

    @on(Input.Changed, "#pl_uri")
    def show_invalid_reasons(self, event: Input.Changed) -> None:
        # Updating the UI to show the reasons why validation failed
        if not event.validation_result.is_valid:
            self.input_error = True

        else:
             self.input_error = False

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions