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

readOnly option change doesn't re-render the <Form /> editability status #533

Open
namti opened this issue Aug 28, 2023 · 2 comments
Open
Assignees

Comments

@namti
Copy link

namti commented Aug 28, 2023

Formio version @formio/[email protected]
React version: 18.2.0

Value change of the readOnly option is not taking effect.

...
const [ editable, setEditable ] = useState(true);

return (
  <Form { ...restProps } options={ { readOnly: editable } } />
)
...

Is there a way to let the <Form /> component trigger the option change?

@namti
Copy link
Author

namti commented Aug 28, 2023

For the temporary solution, I use a random key change to re-render the component manually.

import randomid from 'randomid';
...
const [ editable, setEditable ] = useState(true);
const [ randomKey, setRandomKey ] = useState(randomid(2));

const toggleReadOnly = () => {
  setEditable(!editable);
  setRandomKey(randomid(2));
}

return (
  <Form { ...restProps } key={ randomKey } options={ { readOnly: editable } } />
)
...

@TanyaGashtold
Copy link
Contributor

Thank you for reporting it. We see the issue. If you know how to fix it in our @formio/react library, your PR will be highly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants