Search code examples
javascriptangulartypescriptform-data

FormData boolean field?


I need to use booleans within form data. For example:

let example = new FormData();
example.append('aBoolean', true);

This throws and error as the above 'true' needs to be in string form. Do you know a way I can use booleans within FormData? Alternatively even a way to cast it as a boolean when I get the value by:

example.get("aBoolean")

Assuming i did store the true as a string in the above example.


Solution

  • Well you cannot set Boolean into FormData append method. Only allow datatype are USVString,Blob.

    Read more about it from mdn documentation

    https://developer.mozilla.org/en-US/docs/Web/API/FormData/append

    https://developer.mozilla.org/en-US/docs/Web/API/USVString