react icon indicating copy to clipboard operation
react copied to clipboard

from component is not re-rendering from after changing props.form

Open kalsi8 opened this issue 6 years ago • 9 comments

I am using Form-component with preloaded form json it is not refreshing the form on changing the value of fromProp of the Form tag

code im using : class App extends Component {

constructor(props) { super(props); this.state = { currentUrl: "5c80b71c6bdc0f69544b4e22/", lastValue: {} } } formSubmitted = (value) => { if (value.nextFormId) { this.setState({ currentUrl: value.nextFormId }) } } componentDidMount() { fetch(this.props.baseURL + this.state.currentUrl).then(this.handleFormIoResponce) }

handleFormIoResponce = (responce) => { responce.json().then(value => { console.log(value) this.setState({ lastValue: value }) }) }

render() { let data = "" return ( <Form form={this.state.lastValue} url={this.props.baseURL + this.state.currentUrl} onSubmit={this.formSubmitted} /> ); } }

export default App;

kalsi8 avatar Mar 14 '19 09:03 kalsi8

This should cause the redraw to work: https://github.com/formio/react-formio/blob/master/src/components/Form.js#L108

Is there something we are doing wrong there?

randallknutson avatar Mar 14 '19 14:03 randallknutson

now I am using a workaround for this problem which little bit affects my code's performance: constructor(props) { super(props); this.state = { currentUrl: "5c80b71c6bdc0f69544b4e22", lastValue: "" } } formSubmitted = (value) => { console.log("submitted", value) fetch(this.props.baseURL + this.state.currentUrl + '/submission', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify(value) }).then((responce) => { responce.json().then(value => { console.log("value", value) if (value.nextFormId) { this.setState({ currentUrl: value.nextFormId, lastValue: "" }) this.setState({ lastValue: value.nextForm }) } }) }) } componentDidMount() { fetch(this.props.baseURL + this.state.currentUrl).then(this.handleFormIoResponce) } handleFormIoResponce = (responce) => { responce.json().then(value => { this.setState({ lastValue: value }) }) } render() { let data2 = this.state.lastValue; if (data2 !== "") { console.log("doing", data2) return (

<Form form={data2} url={this.props.baseURL + this.state.currentUrl} onSubmit={this.formSubmitted} />
); } else { return

Data Empty

} }

kalsi8 avatar Mar 15 '19 04:03 kalsi8

also, I want to put one more thing in your notice that the onSubmit is not emitting the event after hitting at the URL provided in (URL) prop to Form component it emits an event with a value of form data so, I am doing is manual in the above-mentioned code.

if you want to reach me you can mail me at [email protected] I will reply to you with my phone number

With Regards Shubham Kalsi

Have a good day Happy Contributing!!

kalsi8 avatar Mar 15 '19 05:03 kalsi8

I'm still not sure what is going wrong here. If you'd like to contact [email protected] we can set up a support plan and get you a support call to resolve any issues you are having.

randallknutson avatar Mar 15 '19 14:03 randallknutson

I have resolved the bug in your code by cloning the source code and making a change in one line( https://github.com/formio/react-formio/blob/master/src/components/Form.js#L108 ) previous:

110: this.formio = formio; 111: this.formio.form = form;

fix:

110: this.formio = formio; 111: this.formio.form = nextProps.form;

I have also forked and changed the file

kalsi8 avatar Mar 15 '19 15:03 kalsi8

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

Hi, I am using Formio Builder and facing the same issue. I am using FormBuilder in the react functional base component and am not able to re-render Formio Builder on state change.

bhawnasemwal123 avatar Feb 05 '24 22:02 bhawnasemwal123

hey @bhawnasemwal123 thanks for the heads up. I'm going to reopen this issue and make sure I include it in some changes that are coming soon

brendanbond avatar Feb 06 '24 02:02 brendanbond