Is it possible to apply FormData to an existing form?

Viewed 3394

If I have an existing form, I know I can effectively "convert" it to FormData by passing the form to the FormData constructor like in this example:

var myForm = document.getElementById('myForm');

var myFormData = new FormData(myForm);
//Now myFormData contains all fields from myForm

Is there any way to effectively do the inverse of this operation? I have an existing FormData object, and I want to apply its fields to a form in the DOM. Something like myForm.setFormData() (which I totally made up in) this example:

var myFormData = new FormData();
myFormData.append(...); //etc...

var myForm = document.getElementById('myForm');
myForm.setFormData(myFormData);
//Now myForm contains all fields from myFormData

Is there any way to apply FormData to an existing form?

1 Answers
Related