Woodchuck
Woodchuck

Reputation: 4414

Set maximum form field length in React Admin

Is there some way to set a field in a SimpleForm within React-Admin to limit the number of characters a user can type into that field?

Based on the docs, the React-Admin framework itself does not appear to contain this functionality. There is validation functionality to show an error when the user types too many characters, but apparently no built-in way to limit the number of characters typed. Given this, has anyone achieved this via other means?

For example, say the valid values for a 'Status' field are only 'A', 'B' or 'C'. How, while using React-Admin, would you limit that form field to accept only 1 character?

Upvotes: 0

Views: 1213

Answers (1)

WiXSL
WiXSL

Reputation: 707

This is not strictly related to react-admin, but here you go:

// react-admin / MUI
<NumberInput inputProps={{ maxLength: 1 }} source="my_source" />

//HTML
<input type="number" maxLength=1 />

Upvotes: 2

Related Questions