Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting values asynchronously in form context does not update the label #44459

Open
falk-stefan opened this issue Nov 18, 2024 · 0 comments
Open
Labels
status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@falk-stefan
Copy link

falk-stefan commented Nov 18, 2024

Steps to reproduce

I am using react-form in combination with the TextField component:

const { register, handleSubmit, reset, formState, watch, setValue } = useForm({
  mode: 'all',
  defaultValues: {
    [label]: value,
  },
});

// ..
<TextField {...register(label, { ...validation })} />

The problem: If value is loaded asynchrounously, the label on top of the text component won't move to the top:

image

I've already tried to setValue:

useEffect(() => {
  setValue(label, value);
}, [label, setValue, value]);

but that didn't work either. It looks like TextField is not reacting to the underlying value changing? Or is this something that's caused by react-form?

Current behavior

No response

Expected behavior

No response

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: useform, textfield, label

@falk-stefan falk-stefan added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

1 participant