Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Material UI OutlinedInput does not display error message

Am using React and material UI to display an outlined input. I can make it display that there has been an error with the error prop set to true but there is an issue when i try to add helperText and my message as a prop:

<OutlinedInput
  margin="dense"
  value=""
  placeholder="my placeholder"
  error
  helperText="There has been an error" // Property 'helperText' does not exist on type 'IntrinsicAttributes & OutlinedInputProps'
/>

Is there any way to use both an OutlinedInput and display an error helper message?

like image 237
RyanP13 Avatar asked Aug 24 '26 14:08

RyanP13


1 Answers

You can use FormHelperText component from @material-ui/core.

const [accountId, setAccountId] = useState({ value: "", error: "" });

<FormControl variant="outlined">
  <InputLabel htmlFor="accountId">Account Id</InputLabel>
  <OutlinedInput
    value={accountId.value}
    onChange={(e) => setAccountId({value: e.target.value, error:""})}
    inputProps={{
      "aria-label": "Account Id",
    }}
    labelWidth={74}
    error={!!accountId.error}
  />
  {!!accountId.error && (
    <FormHelperText error id="accountId-error">
      {accountId.error}
    </FormHelperText>
  )}
</FormControl>
like image 126
Nitesh Tosniwal Avatar answered Aug 27 '26 04:08

Nitesh Tosniwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!