Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
Reset form method not working in timepicker

I am trying to reset the form value when clicking the reset button. But when I reset the form that time rest of the form fields reset except the time picker field.

I am using controller hooks form and MUI TimePicker.

import { useFormContext, Controller } from 'react-hook-form';
import { TimePicker } from '@mui/lab';

const dispatch = useDispatch();
const methods = useFormContext();
const { formState, watch, getValues, reset } = methods;
const { isValid, dirtyFields } = formState;

const [morningShiftStartValue, setMorningShiftStartValue] = useState(null));


<Controller
    name="morningShiftStartTime"
    id="morningShiftStartTime"
    control={control}
    render={({ field }) => (
        <TimePicker
        name="morningShiftStartTime"
        label="Morning Shift Start Time"
        value={morningShiftStartValue}
        ampm={false}
        onChange={(newValue) => {
          field.onChange(newValue);
          setMorningShiftStartValue(newValue);
        }}
        renderInput={(field) => <TextField {...field} />}
      />
    )}
  />

Also set initial default value null or "" but still not worked.

Please help me to resolve this issue.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This happens because you are storing value of your timePicker in useState instead of in Controller (i suppose that you are using hookform). Just take value to takepicker from Controller

value={field.value}

or you can just destructuralize whole value in your TimePicker if there is no need to keep value separately


<Controller
    name="morningShiftStartTime"
    id="morningShiftStartTime"
    control={control}
    render={({field:{onChange, ...field}}) => (
        <TimePicker
        name="morningShiftStartTime"
        label="Morning Shift Start Time"
        ampm={false}
        renderInput={(field) => <TextField {...field} />}
        onChange={(e)=>onChange(e.target.value)}
        {...field}
      />
    )}
  />
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!