React-hook-form: Passing type="password" to controller MUI textfield throws a warning.

Created on 13 Feb 2020  ·  3Comments  ·  Source: react-hook-form/react-hook-form


Just started playing around with react-hook-form and have been getting this weird warning every time I try to make a password field.

          <Controller
            as={<TextField/>}
            control={control}
            variant="outlined"
            margin="normal"
            required
            fullWidth
            name="password"
            label="Password"
            type="password"
            id="password"
            autoComplete="current-password"
          />

Screen Shot 2020-02-12 at 3 35 05 PM

When I comment out type="password" the warning goes away.

          <Controller
            as={<TextField/>}
            control={control}
            variant="outlined"
            margin="normal"
            required
            fullWidth
            name="password"
            label="Password"
            // type="password"
            id="password"
            autoComplete="current-password"
          />

Any idea what's happening here? Is there a way to flag this field as a password field without getting a warning? Other fields without password type seem to work fine.

Thanks.

question

All 3 comments

defaultValue: https://react-hook-form.com/api#Controller check out the doc it's changing from uncontrolled to controlled.

That was exactly it. Thanks @bluebill1049. I'll close the thread now. For anyone who stumbles upon this in the future here's the solution:

          <Controller
            as={<TextField/>}
            control={control}
            variant="outlined"
            margin="normal"
            required
            fullWidth
            name="password"
            label="Password"
            type="password"
            id="password"
            autoComplete="current-password"
            // added default value
            defaultValue={{ value: '' }}
          />

thanks for sharing answer too :) @TimothyStiles

Was this page helpful?
0 / 5 - 0 ratings