Skip to content

Number input can emit empty value changes#24673

Open
perry-blueberry wants to merge 2 commits into
bevyengine:mainfrom
perry-blueberry:emit-value-change-on-empty-text
Open

Number input can emit empty value changes#24673
perry-blueberry wants to merge 2 commits into
bevyengine:mainfrom
perry-blueberry:emit-value-change-on-empty-text

Conversation

@perry-blueberry

Copy link
Copy Markdown

Objective

Currently there's no event that emits a number input has changed to the empty value. You can do On<ValueChange<f32>> but you cannot do On<ValueChange<Option<f32>>>. This adds that possibility with the emit_value_change_on_empty prop added. This is set to false by default so the previous behavior will be used by default.

Solution

Adds emit_value_change_on_empty to FeathersNumberInputProps to change the event to emit On<ValueChange<Option<T>>>. Add Empty to NumberInputValue to be able to set the value back.

I'm not 100% sure how template_value works but I hope I did that part correctly.

Testing

I've updated the feathers_gallery example to have the scalar value be able to be empty.

Showcase

Click to view showcase bild

Also changed the example to have the scalar be optional.
@kfc35 kfc35 added A-Text Rendering and layout for characters S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 20, 2026
commands: &mut Commands,
number_type_str: &str,
) {
if allow_empty && text_value.is_empty() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would move the logic of

if !allow_empty && text_value.is_empty() {
        return;
    }

from emit_value_change into this function block

Otherwise, it appears that this case isn’t explicitly handled in this fn as is. The else block doesn’t appear to handle that case correctly (since it’s assuming the logic happened outside the function), so it can cause a moment of confusion.

@kfc35 kfc35 added D-Straightforward Simple bug fixes and API improvements, docs, test and examples C-Feature A new feature, making something new possible labels Jun 20, 2026
@viridia

viridia commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

I don't think this is the right answer. A better approach might be to add a dedicated "error" event.

This gets into the whole topic of field validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Text Rendering and layout for characters C-Feature A new feature, making something new possible D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants