formio.js icon indicating copy to clipboard operation
formio.js copied to clipboard

Form is rendering before data submission is ready

Open celu opened this issue 1 year ago • 5 comments

I'm using formio with Angular,

Then I'm creating a form with a component that in advanced logic as javascript trigger condition that uses a var owner = data.OWNER; that depends on data.

When the form is created in angular with Formio.createForm(             document.getElementById('formio'),             this.form,             options,         ).then((form) => {            form.submission = this.formioSubmission; }

The data arrives if i display a console.log but the console log prints multiple times undefined before gettings its value since the form is being rendered and the data is then loaded at the submission so the owner = data.OWNER; executes before the data is available.

Is there a better approach to use the data of the form or to wait until the form is rendered or is it a bug?

Version/Branch Formiojs: 4.21.4 Formio/angular: 7.0.0

Expected behavior Getting the data values before JavaScript in logic trigger is loaded.

celu avatar Nov 28 '24 07:11 celu

I've found workaround for this, you can use evalContext property for configuration, and pass via it anything you want to be available for form in runtime.

In this scenario u can pass

evalContext: { initData: someData }

and then you can use initData like for exmaple data for custom default value

maybe that will suits for you

documentation

jgrott avatar Dec 16 '24 08:12 jgrott

I've found workaround for this, you can use evalContext property for configuration, and pass via it anything you want to be available for form in runtime.

In this scenario u can pass

evalContext: { initData: someData }

and then you can use initData like for exmaple data for custom default value

maybe that will suits for you

documentation

I've already tried this method but it won't fully work since it won't validate in the backend when the data is sent to nodejs

celu avatar Dec 16 '24 11:12 celu

ahh, so good luck with finding other way :/

jgrott avatar Dec 16 '24 11:12 jgrott

Can you provide a jsfiddle or some sort of code sandbox to illustrate what you are trying to do?

lane-formio avatar Jan 23 '25 15:01 lane-formio

This is a duplicate of https://github.com/formio/formio.js/issues/3687

paulfalgout avatar Jan 27 '25 18:01 paulfalgout