formio / react

JSON powered forms for React.js
https://form.io
MIT License
305 stars 267 forks source link

[BUG] Form does not change language when options change #410

Open madflow opened 2 years ago

madflow commented 2 years ago

Environment

Please provide as many details as you can:

Steps to Reproduce

  1. Use React and Formio with i18next.
  2. Configure everything something like this:
  const options = {
    i18n: {
      [i18n.language]: i18n.getResourceBundle(i18n.language, 'translation'),
    },
    language: i18n.language,
    hooks: {},
  };

// https://help.form.io/developers/form-renderer#form-renderer-options
  return (
    <>
      <Form
        src={url}
        onSubmitDone={onSubmitDone}
        formReady={onFormReady}
        options={options}
      />
      {isReady ? null : <LoadingSpinner animation="border" />}
    </>
  );
  1. Change the language

Expected behavior

Kapture 2021-09-27 at 17 53 35

Observed behavior

Kapture 2021-09-27 at 17 56 29

This can be hack-fixed by amending Form.jsx , https://github.com/formio/react/blob/e9d61b0dc7ec45be966fd57b92c41e9b9f8483ab/src/components/Form.jsx#L62

  useEffect(() => {
    const { src } = props;
    if (src) {
      createWebformInstance(src).then(() => {
        if (formio) {
          formio.src = src;
        }
      });
      initializeFormio();
    }
  }, [props.src, props.options]);
rijusougata13 commented 2 years ago

hi @madflow can you assign me here?

madflow commented 2 years ago

@rijusougata13 No, I cannot assign you.

rafapsm commented 2 years ago

@madflow @rijusougata13 Is there a solution for this problem. I am facing the same issue. Thanks

travist commented 2 years ago

We added this for our Monday planning to get this prioritized. Thanks.

PatrikWing commented 1 year ago

Having the same issue.

lane-formio commented 1 month ago

We've done some work recently around translations. Can you try again with the latest rc versions to see if this has resolved?

madflow commented 1 week ago

@lane-formio

I have installed the latest RC Version, which required a npm namespace change using the "formiojs" now as @formio/js library. I tried a full update:

 yarn add @formio/js @formio/react @formio/premium

This resulted in:

    "@formio/js": "5.0.0-rc.48",
    "@formio/premium": "^2.0.3",
    "@formio/react": "^5.3.1-dev.AvA08V.6",

Changing the language and passing it down as prop (see initial first post) is still not working.

Also, the `@formio/premium" package does not build properly and the complete build fails (I had to disable it to test the language changes). It seems, that the premium package does not know about the name change yet.

✘ [ERROR] Could not resolve "formiojs"

    node_modules/@formio/premium/lib/components/Sketchpad/Sketchpad.form.js:8:27:
      8 │ import { Components } from 'formiojs';
        ╵                            ~~~~~~~~~~

  You can mark the path "formiojs" as external to exclude it from the bundle, which will remove this
  error.

✘ [ERROR] Could not resolve "formiojs"

    node_modules/@formio/premium/lib/utils/utils.js:14:45:
      14 │ import { Utils as FormioUtils, Formio } from 'formiojs';
         ╵                                              ~~~~~~~~~~

  You can mark the path "formiojs" as external to exclude it from the bundle, which will remove this
  error.

✘ [ERROR] Could not resolve "formiojs"

    node_modules/@formio/premium/lib/components/DynamicWizard/editForm/DynamicWizard.edit.templates.js:1:22:
      1 │ import { Utils } from 'formiojs';
        ╵                       ~~~~~~~~~~

  You can mark the path "formiojs" as external to exclude it from the bundle, which will remove this
  error.

✘ [ERROR] Could not resolve "formiojs"

    node_modules/@formio/premium/lib/components/DataTable/DataTableFormioIntegration.js:19:37:
      19 │ import { Components, Builders } from 'formiojs';
         ╵                                      ~~~~~~~~~~

  You can mark the path "formiojs" as external to exclude it from the bundle, which will remove this
  error.

✘ [ERROR] Could not resolve "formiojs"

    node_modules/@formio/premium/lib/components/DataTable/DataTable.form.js:8:27:
      8 │ import { Components } from 'formiojs';
        ╵                            ~~~~~~~~~~

  You can mark the path "formiojs" as external to exclude it from the bundle, which will remove this
  error.

✘ [ERROR] Could not resolve "formiojs"

    node_modules/@formio/premium/lib/components/Captcha/editForm/Captcha.edit.display.js:1:22:
      1 │ import { Utils } from 'formiojs';
        ╵                       ~~~~~~~~~~
lane-formio commented 1 week ago

Apologies, try @formio/react@6.0.0-rc.1