Skip to content

InputGroup breaks Form Field validation #527

@ng-hai

Description

@ng-hai

mui/base-ui#1844

I tried this sample code to see why the FieldError did not show up. And surprisingly, it’s because of the InputGroup wrapper. If I bring the FieldControl (Input, NumberField) out of the InputGroup, everything is fine.

<Form validationMode="onChange">
  <Field
    validate={(value) => {
      if (value === undefined || value == null || value === 0) {
        return "Amount is required";
      }
      if (typeof value === "number" && Number.isFinite(value)) {
        if (value > 50) {
          return "Insufficient balance, your remaining balance is 50.00";
        }
        if (value < 20) {
          return "The minimum amount is 20.00";
        }
      }
      return null;
    }}
  >
    <FieldLabel>Withdrawal amount</FieldLabel>

    <InputGroup>
      <NumberField required>
        <NumberFieldInput placeholder="Maximum [x] per day" />
      </NumberField>
    </InputGroup>

    <FieldError match="customError" />
  </Field.Root>
</Form.Root>

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