Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are rules supposed to be composable by default? #13

Closed
thohan88 opened this issue Jan 9, 2025 · 1 comment · Fixed by #14
Closed

Are rules supposed to be composable by default? #13

thohan88 opened this issue Jan 9, 2025 · 1 comment · Fixed by #14

Comments

@thohan88
Copy link

thohan88 commented Jan 9, 2025

In the provided examples, rules appear to be composable when defined in sequence by default:

iv.add_rule("email", check.required())
iv.add_rule("email", check.email())

iv.add_rule("email", check.required())
iv.add_rule("email", check.email())

However, this does not seem to be the case in practice:

from shiny import App, ui
from shiny_validate import check, InputValidator

app_ui = ui.page_auto(
    ui.input_text("sequential", "Sequential rules"),
    ui.input_text("composed", "Composed rules"),
)


def server(input, output, session):

    set = ["1", "2", ""]

    iv = InputValidator()
    iv.add_rule("sequential", check.required())  # This rule is ignored
    iv.add_rule("sequential", check.in_set(set)) # This rule is enforced
    iv.add_rule("composed", check.compose_rules(check.required(), check.in_set(set)))
    iv.enable()


app = App(app_ui, server)

shinylive

The last rule for for sequential takes precedence here.

Image
@gadenbuie
Copy link
Contributor

Thanks @thohan88! You're right, .add_rule() is intended to add a new rule that's evaluated after previous rules. I just made a change in #14 that should fix this.

If you try it and it gives you any issues please let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants