Skip to content

BitNumberField displayed value may be inconsistent with the actual current value #11926

@Greexter

Description

@Greexter

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When using contraints Min or Max (or Precission), inputting value out of bounds will display corrected value only for the first change. For example with max set to 10:

Image

  1. After first 1000 input, corrected 10 is displ.ayed
  2. Entering 1000 again and submitting using enter will not display 10 although internally 10 should be the current value

The reason behind this seems to be that the component does not use :get and :set modifiers for binding.

Changing the code to use the modifiers seems to fix the issue:

            <input @ref="InputElement" @attributes="@InputHtmlAttributes"
                   @onblur="HandleOnBlur"
                   @onfocus="HandleOnFocus"
                   @onkeydown="HandleOnKeyDown"
                   @onfocusin="HandleOnFocusIn"
                   @onfocusout="HandleOnFocusOut"
                   @onwheel="HandleOnMouseWheel"
                   form=""
                   min="@_min"
                   max="@_max"
                   name="@Name"
                   step="@_step"
                   id="@_inputId"
                   readonly="@(ReadOnly || IsInputReadOnly)"
                   required="@Required"
                   style="@Styles?.Input"
                   autofocus="@AutoFocus"
                   inputmode="@_inputMode"
                   placeholder="@Placeholder"
                   aria-labelledby="@_labelId"
                   @bind-value:get="@CurrentValueAsString"
                   @bind-value:set="val => Immediate ? HandleOnStringValueInputAsync(new ChangeEventArgs() { Value = val }) : HandleOnStringValueChangeAsync(new ChangeEventArgs() { Value = val })"
                   @bind-value:event="@(Immediate ? "oninput" : "onchange")"
                   disabled="@(IsEnabled is false)"
                   class="bit-nfl-inp@(Mode == BitSpinButtonMode.Spread ? " bit-nfl-cin" : "") @Classes?.Input"
                   autocomplete="@(AutoComplete ?? "off")"
                   type="text"
                   aria-valuemin="@_min"
                   aria-valuemax="@_max"
                   aria-describedby="@AriaDescription"
                   aria-valuenow="@(AriaValueNow ?? CurrentValue)"
                   aria-valuetext="@(AriaValueText ?? CurrentValueAsString)"
                   aria-disabled="@(IsEnabled is false)" />

Image

Expected Behavior

The component should display the current value after correction and not the invalid out of bound value after value change.

Steps To Reproduce

Reproducible in the documentation examples.

  1. Enter value out of bounds
  2. Press enter
  3. Value clamped to the limits and displayed
  4. Enter out of bounds again
  5. Press enter
  6. Displayed value stays the same

Exceptions (if any)

No response

.NET Version

.net 10

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions