question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot update data in view after put request because data gets reset after successful submission

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
raniesantoscommented, Apr 18, 2017

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.

data() {
    return {
        form: new Form({
            firstname: '',
            lastname: '',
            location: ''
        }, {
            reset: false
        })
    }
},
0reactions
sebastiandedeynecommented, May 19, 2017

I added an options parameter in 1.5.0.

const form = new Form(fields, { resetOnSuccess: false });
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found