почему обязательная проверка не работает в средстве выбора даты?

когда я нажимаю кнопку отправки. не отображается Обязательная ошибка, поскольку это обязательное поле. вот мой код. Я уже зарегистрировался с обязательным и также пытался использовать правило, но все еще не получил требуемую проверку

<MuiPickersUtilsProvider utils={DateFnsUtils}>
    <Controller
        as={
            <KeyboardDatePicker
                autoOk
                disableToolbar
                variant="inline"
                format="MM/dd/yyyy"
                id={"appointmentDate"}
                inputVariant="outlined"
                inputRef={register({ required: true })}
                label={"Appointment Date"}
                required={true}
                helperText={errors["appointmentDate"] && "Required..!!"}
                error={errors["appointmentDate"] ? true : false}
                KeyboardButtonProps={{
                    "aria-label": "change date"
                }}
            />
        }
        rules={{ validate: value => value === null || "Required ..!!" }}
        name={"appointmentDate"}
        control={control}
    />
</MuiPickersUtilsProvider>

https://codesandbox.io/s/mui-autocomplete-with-react-hook-form-1p3x5


person user944513    schedule 12.02.2020    source источник


Ответы (1)


Вот фиксированный код

        <Controller
          as={
            <KeyboardDatePicker
              autoOk
              disableToolbar
              variant="inline"
              format="MM/dd/yyyy"
              id={"appointmentDate"}
              //  inputRef={register({ required: true })}  // not required remove this
              inputVariant="outlined"
              label={"Appointment Date"}
              required={true}
              helperText={errors["appointmentDate"] && "Required..!!"}
              error={errors["appointmentDate"] ? true : false}
              KeyboardButtonProps={{
                "aria-label": "change date"
              }}
            />
          }
          // rules={{ validate: value => value === null || "Required ..!!" }} // change this like below
          rules={{ required: true }}
          name="appointmentDate"
          control={control}
        />

https://codesandbox.io/s/mui-autocomplete-with-react-hook-form-iymgr

person syJSdev    schedule 12.02.2020