Kendo React Form is not updating when passing Key value - after a post request

1 Answer 699 Views
Form
Mareena
Top achievements
Rank 1
Mareena asked on 01 Dec 2022, 02:43 AM

I have a Form and I'm entering some data to the fields and submitting data to backend using OnSubmit method, After submission I wanted to see my page with already submitted data. Instead page is reloading with previous item. I tried to pass new object with all the latest values to form in the Key attribute. But Form is not reloading with the new data that I supplied.

my code like this.

//submit method

var option;

const SubmitData = async (request, e) => {

option = request;

try{

await postData(request).unwrap().then(() => )

}

}

 

// Form

return (
    <Page>
      <Form
        initialValues={workProgramDetailsResponse}
        onSubmit={SubmitData }
        key={option}
       

render={(formRenderProps) => (

<div><FormElement>------</FormElement></div>)}

I'm creating a global variable and trying to pass it in the key. IS this a correct approach? Or key value should match with initialValues(varibale names) - data structure inside both are same.

 

Please help

 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 02 Dec 2022, 01:32 PM

Hello Mareena,

Thank you for reaching out to us.

The form will display the initialValue when it is initialized and if there are changes afterwards (for example if you want to reset the form or clear it with new initial values), you need to change the initialValues and change the "key" value. The key value does not have to be an object with the new values and the only requirement is that it is a different value from the old one. You can use an incrementing integer value or "new Date()" every time you want to re-mount the Form with the new initial values.

Hope this helps.

 

Regards,
Konstantin Dikov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Form
Asked by
Mareena
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or