Skip to content

Input.valid_empty incorrectly ignored #5917

@holdenweb

Description

@holdenweb

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

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

The bug

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.

The following test, which fails under the current production textual, demonstrates that an Input with valid_empty=False is valid when created with non-empty content, but is not invalidated when the content is deleted.

from textual.app import App, ComposeResult
from textual.widgets import Input
import pytest
import pytest_asyncio

@pytest.mark.asyncio
async def test_invalid_empty():

    class InvalidEmptyApp(App):

        def compose(self) -> ComposeResult:
            yield Input(valid_empty=False, id="test-in", value="x")

    app = InvalidEmptyApp()
    async with app.run_test() as pilot:
        input = app.query_one(Input)

        assert input.has_class('-valid')
        assert not input.has_class('-invalid')

        await pilot.press('backspace')

        assert input.has_class('-invalid')
        assert not input.has_class('-valid')

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

textual diagnose

<!-- This is valid Markdown, please paste the following directly in to a GitHub issue -->
# Textual Diagnostics

## Versions

| Name    | Value  |
|---------|--------|
| Textual | 3.5.0  |
| Rich    | 14.0.0 |

## Python

| Name           | Value                                                         |
|----------------|---------------------------------------------------------------|
| Version        | 3.12.8                                                        |
| Implementation | CPython                                                       |
| Compiler       | Clang 19.1.6                                                  |
| Executable     | /Users/sholden/Projects/Python/textual-forms/.venv/bin/python |

## Operating System

| Name    | Value                                                                                                  |
|---------|--------------------------------------------------------------------------------------------------------|
| System  | Darwin                                                                                                 |
| Release | 24.5.0                                                                                                 |
| Version | Darwin Kernel Version 24.5.0: Tue Apr 22 19:48:46 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T8103 |

## Terminal

| Name                 | Value              |
|----------------------|--------------------|
| Terminal Application | iTerm.app (3.5.14) |
| TERM                 | rxvt               |
| COLORTERM            | truecolor          |
| FORCE_COLOR          | *Not set*          |
| NO_COLOR             | *Not set*          |

## Rich Console options

| Name           | Value               |
|----------------|---------------------|
| size           | width=80, height=37 |
| legacy_windows | False               |
| min_width      | 1                   |
| max_width      | 80                  |
| is_terminal    | False               |
| encoding       | utf-8               |
| max_height     | 37                  |
| justify        | None                |
| overflow       | None                |
| no_wrap        | False               |
| highlight      | None                |
| markup         | None                |
| height         | None                |


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!

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