1

Could not find the correct way to have only positive numbers in an MUI text field of type='number'

Here is my Field

<TextField
    name={name}
    type={props.type || 'text'}
    label={props.label}
    helperText={errorMessage}
    variant={props.variant}
    multiline={props.multiline}
    required={props.required}
    value={props.value}
    defaultValue={props.initialValue}
    rows={props.rows}
    size={props.size}
    InputProps={{
      readOnly: props.readonly, startAdornment: props.startAdornmentText && <InputAdornment position='start'>{props.startAdornmentText}</InputAdornment>,
      }}
  
  Need to add Min value of 0, I guess it will be in the InputProps, like {min:0} but did not work  
      
 

Thanks

user34564
  • 21
  • 2

1 Answers1

0

You can do it with the prop

inputProps={{ min: 4, max: 10 }}

and also controlling the value with the onChange or value={value > min ? value : 0}

here is more info https://stackoverflow.com/a/67072685/10286595

Salo Avalos
  • 80
  • 1
  • 6