react icon indicating copy to clipboard operation
react copied to clipboard

FormEdit isn't updated with server data

Open Andrey-Pavlov opened this issue 4 years ago • 3 comments

The test case

const [form, setForm] = useState({display: 'form'});
 const [saveText, setSaveText] = useState('Create Form');

  useEffect(() => {
    async function getFormBuilderData()
    {
      const res = await axios.get('/api/editor');
      setForm(res.data);
    }

    getFormBuilderData();
  }, []);

  return <>
      <FormEdit form={form} saveText={saveText} saveForm={saveForm} options={{
        builder: {
          layout: false,
          premium: false,
          data: false,
        }
      }}

I can't see saved controls. I think the issue in the next code section of FormEdit: https://github.com/formio/react-formio/blob/master/src/components/FormEdit.jsx

  shouldComponentUpdate(nextProps, nextState, nextContext) {
    // Only update if key form info has changed. The builder handles form component changes itself.
    return (
      this.state.form.title !== nextState.form.title ||
      this.state.form.name !== nextState.form.name ||
      this.state.form.path !== nextState.form.path ||
      this.state.form.display !== nextState.form.display ||
      this.state.form.type !== nextState.form.type
    );
  }

or this

  static getDerivedStateFromProps(nextProps, prevState) {
    if (nextProps.form && (prevState.form._id !== nextProps.form._id || prevState.form.modified !== nextProps.form.modified)) {
      return {
        form: _cloneDeep(nextProps.form),
      };
    }

    return null;
  }

None of them checks controls difference. getDerivedStateFromProps set state only if new object has modified or _id properties

Andrey-Pavlov avatar Apr 13 '20 13:04 Andrey-Pavlov

@Andrey-Pavlov,

We have added this item to our backlog. We welcome a pull request for this item to be resolved or we have a process to expedite this issue if you are interested. Please contact [email protected] if you would like the price to expedite this for you.

Thank you,

William Gay

wag110894 avatar Apr 13 '20 15:04 wag110894

@Andrey-Pavlov @wag110894 There is no start script while I downloaded the sorce code , So i add a custom webpack file and run the application But which is the main file that is responsible for the page loading so that i can customize the whole components inside project ...Can you pls let me know

rahulseth625 avatar Jan 28 '21 11:01 rahulseth625

@rahulseth625 This repository is just a library. It isn't meant to be used as an actual application. You should use components from this library to utilize your own react application.

AlexeyDavyd avatar Jan 29 '21 09:01 AlexeyDavyd

I am closing the issue as it was created too long ago and there are no new comments here. I hope it was resolved. If not, please reopen it. Thanks!

TanyaGashtold avatar Aug 31 '23 13:08 TanyaGashtold

Hello @TanyaGashtold. It was not fixed but I changed multiple projects, workplaces and got a child. Thank you.

Andrey-Pavlov avatar Aug 31 '23 19:08 Andrey-Pavlov