Closed ryan-ds17 closed 6 years ago
I think that it's not a big deal. You can do something like that.
var form_data = new FormData();
for ( var key in myForm.value ) {
form_data.append(key, item[key]);
}
Yes it works. Thank you
I had another doubt. When I use input type="number"
for a form control I have, when I submit the form, that value is changed to a string. How can I prevent this from happening?
Actually input type="number"
always returns a string.
Check it here.
So, if you want to use the value as a number
instead of string
then you can use parseInt
to parse the string as a number.
Btw, I'm planning to add normalizers & parsers in next version.
Where would I use parseInt?
If you're using multipart form data then you don't need to parse because .append
will change the number to string.
If you really want to do that then you can do something like that before submitting the form values.
const formData = {};
Object.keys(myForm.value).forEach((name) => {
let value = myForm.value[name];
if(name === "age") {
value = parseInt(value, 10);
}
formData[name] = value;
});
This issue is not active since a long time.
Does this work with multipart form data?