Closed BennyAlex closed 1 year ago
Hey ! There is no difference with the current version because the required
prop is only applied to the TextField (restTextFieldProps
which contains the required
prop is already spread to the TextField
component).
I mean, here, I don't see any changes.
But its also spread to InputProps I think.
Nop, we only spread the InputProps
prop to the InputProps
of TextField.
https://codesandbox.io/s/mui-chips-input-forked-kju5uw Ah okay, than we need another workaround? As you can see, the browser throws an error even chips have been set.
It works if setting clearInputOnBlur={false} and you type someting inside the field, buts this is of course not really a solution.
Nah, you have to remove the required prop, and create your own validation rule.
before submitting your form, you have to check if value.length > 0
, if not, display your own error message
@viclafouch Hey, thanks for answer. This of course remove the browser validation, but it also removes the MUI styling for required fields... So maybe the fix is to set required for inputProps (written in lowercase for the element props) to false, so there is no browser check going on?
https://codesandbox.io/s/mui-chips-input-forked-kju5uw?file=/src/App.js
looks like this will work.
@viclafouch I think if this should be included by default, since browser validation will always fail with chips input, so this is more or less a bug. The developer always has to do his own validation anyways and by just overwriting required in inputProps, he stil can make it in required style by setting required true on the chips input component itself.
Hello,
currently, the required prop got passed to the input itself. This is not neccessary, as stated in the MUI docs, required has only to be set on the TextField. Currently this causes a problem with forms, since setting the element to required triggers browser validation (saying this field is required) and the input field itself is empty even chips are shown. This should fix this error.