Form and New FormData

Hi, i have a form that has 6 field. When a user click on submit i would like to add a new field containing a token (recapcha v3).

I am trying to use

var formData = new FormData(someFormElement);

But not sure what to use for “someFormElement” to include the 6 field.

Then i will use the append to add the recapcha token

formData.append(“recapcha”, token);

Everything i tried always return a:

Uncaught TypeError: Failed to construct ‘FormData’: parameter 1 is not of type ‘HTMLFormElement’.

Of course i could just create a new empty formData and then append all 6 field with getValues()… But i would like to know if it is possible to simply create a new formData with existing webix form.

No one has any suggestion? Just want to add a new hidden input on a form when the user click submit.

Loop like this work, but i would of like a one line solution …

var list = form.getValues();
var formData = new FormData();
for ( var key in list ) {
formData.append(key, list[key]);
}

it depends on how you want to use this FormData.
if you must use FormData class and want one line solution then you can define some helper function like this

function formDataFromPlainObject(obj) {
    var form = new FormData();
    for(var key in obj) {
        form.append(key, obj[key]);
    } 
    return form;
}

but in real word it is enough to extend form values with any data.

var obj = webix.extend({recapcha:token}, form.getValues());