Cannot update data in view after put request because data gets reset after successful submission
See original GitHub issueI have a form with a single text field named content
.
Let’s say it’s default value is “Taylor”.
And then I type into the field and change it’s value to “Jeffrey”.
After a successful put request, I want to emit the updated value (which is Jeffrey) to the parent to reflect the change in the view.
onUpdateQuote() {
// At this point in the code, the value of this.form.content is "Jeffrey"
// since I typed into the form and changed it
console.log('before ajax request: ' + this.form.content);
this.form.put(appUrl.api('/quote/update/' + this.qt.id).withToken())
.then(response => {
// However, upon success, the value of this.form.content goes back to "Taylor"
// I wish to send the updated value "Jeffrey" via $emit
// but I can't because it has been reset
console.log('after ajax request: ' + this.form.content);
this.editing = false;
this.$emit('quoteUpdated', {
id: this.qt.id,
content: this.form.content
});
// this.$store.commit('setAlert', response.message);
})
.catch(error => console.log(error));
}
Is this actually the intended behavior?
EDIT: I saw this in the code so I guess it was intended. What if you make it so that put requests don’t execute a form reset? Are there any cases where it would cause problems?
onSuccess() {
this.reset();
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
clear form values after submission ajax - Stack Overflow
This code will work perfectly but in case you are not using any form tag then you can try to set an empty...
Read more >Remix Single: Clearing Inputs After Form Submissions
After a form submission completes, you often want to clear out the form fields. You can `useTransition` to know when to reset the...
Read more >Mutations in Apollo Client - Apollo GraphQL Docs
When a mutation's response is insufficient to update all modified fields in your cache (such as certain list fields), you can define an...
Read more >[Apple Watch] Unable to Check for Update - Apple Developer
Hi. I am pairing my Apple Watch Series 5 to my iPhone running ios 14. The pairing is successful but unable to proceed...
Read more >Troubleshoot refresh scenarios - Power BI - Microsoft Learn
This article provides ways to troubleshoot issues with refreshing data within the Power BI service, for various data sources and conditions.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just a follow-up idea, since the Form constructor currently only takes form data as the first and only parameter, maybe it can have a second optional parameter to take in certain options (just like most javascript libraries, except in this case the options are the 2nd parameter) such as setting the reset behavior to false.
I added an
options
parameter in1.5.0
.