Form data

Reading & writing form data via functions

There are 4 main functions for getting and setting values:

  • getValue

  • getJsonValue

  • setValue

  • setJsonValue

All form controls have this function. Example:

const form = await JsfBuilder.create({ /* your schema definition */ });

const allData = form.getValue();
const email = form.getProp('user.email').getValue();

form.getProp('user.email').setValue('example@example.com');

Reading and writing via value proxy

Sometimes you might like to use a more natural way of reading and changing values. For that purpose value property exists on form instance. Under the hood we are using Proxy and calling getValue and setValue functions for every get and set, meaning that for every read you will get copy of data (references are not the same).

Example:

const form: JsfBuilder<MyValueInterface> = await JsfBuilder.create({ /* your schema definition */ });

form.value.user.email = 'test@example.com';
// ... is same as ...
form.getProp('user.email').setValue('test@example.com');


console.log(form.value.user.email);
// ... is same as ...
console.log(form.getProp('user.email').getValue());

// Arrays also work
form.value.cities[42].name = 'Ljubljana';

Last updated

Was this helpful?