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

MaskedInput ValueError Value does not match template #5493

Open
JonathanPlasse opened this issue Jan 24, 2025 · 3 comments · May be fixed by #5494
Open

MaskedInput ValueError Value does not match template #5493

JonathanPlasse opened this issue Jan 24, 2025 · 3 comments · May be fixed by #5494

Comments

@JonathanPlasse
Copy link

Have you checked closed issues? https://github.com/Textualize/textual/issues?q=is%3Aissue+is%3Aclosed

Yes, no issue mentioned problems with MaskedInput validation.

Have you checked against the most recent version of Textual? https://pypi.org/search/?q=textual

Yes

Please give a brief but clear explanation of the issue. If you can, include a complete working example that demonstrates the bug. Check it can run without modifications.

  1. Run the app
uv run --script masked_input_value_error.py
  1. Press the key e or any other non digit.
  2. Watch the app crash with a ValueError.

masked_input_value_error.py

# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "textual==1.0.0",
# ]
# ///
from textual.app import App, ComposeResult
from textual.widgets import MaskedInput


class BugApp(App[None]):
    def compose(self) -> ComposeResult:
        yield MaskedInput("9", "9")


app = BugApp()
app.run()

It will be helpful if you run the following command and paste the results:

textual diagnose

If you don't have the textual command on your path, you may have forgotten to install the textual-dev package.

Feel free to add screenshots and / or videos. These can be very helpful!

Screencast.from.2025-01-24.22-33-57.mp4

Image

Image

Textual Diagnostics

Versions

Name Value
Textual 1.0.0
Rich 13.9.4

Python

Name Value
Version 3.13.0
Implementation CPython
Compiler Clang 18.1.8
Executable /home/jonathan/.cache/uv/archive-v0/uhCuU97F8DMiIyfN6OiqV/bin/python

Operating System

Name Value
System Linux
Release 6.12.9-100.fc40.x86_64
Version #1 SMP PREEMPT_DYNAMIC Thu Jan 9 16:04:00 UTC 2025

Terminal

Name Value
Terminal Application vscode (1.96.4)
TERM xterm-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=142, height=23
legacy_windows False
min_width 1
max_width 142
is_terminal True
encoding utf-8
max_height 23
justify None
overflow None
no_wrap False
highlight None
markup None
height None
Copy link

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@JonathanPlasse
Copy link
Author

After some investigation, it seems that the problem comes from MaskedInput not implementing replace to filter out bad characters.
How should MaskedInput behave when the text is selected but the inputted value is invalid?

  • Should the inputted value be ignored and keep the old value?
  • Should the inputted value be modified to use spaces instead of invalid characters?

@JonathanPlasse JonathanPlasse linked a pull request Jan 24, 2025 that will close this issue
3 tasks
@TomJGooding
Copy link
Contributor

TomJGooding commented Jan 25, 2025

Good catch. I think this also shows another problem with the MaskedInput which I've raised as a separate issue:

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