🌊
jsf
  • About KalmiaJSF
  • Setup
  • Architecture
  • Contributing
  • Changelog
  • Guides
    • Cheat Sheet
  • Examples
    • Demo example
    • Basic examples
    • Kitchen Sink example
    • Charts example
  • Schema
    • Intro to Schema
    • Prop types
      • String
      • Boolean
      • Number & Integer
      • Object
      • Array
      • Date
      • Id
      • Null
      • Ref
      • Binary
    • Prop options
      • Disabling property
      • On prop init actions
      • Persist
      • On value change
      • On user value change
    • Handlers
      • Color picker
    • Creating custom handler
      • Working with arrays
    • Value provider
  • Validation
    • Custom validation
    • Eval
  • LAYOUT
    • Intro to Layout
    • Layout options
      • Show & hide
      • On click action
  • INTERFACES
    • Value Options
  • Form
    • Form data
  • OTHER
    • Events
    • Lifecycle hooks
    • Notifications support
  • PAGES & COMPONENTS
    • Page
    • Component
  • THEMING
    • Creating new theme variant
  • BUILDER
    • Shortcuts
  • Help
    • FAQ
Powered by GitBook
On this page
  • Reading & writing form data via functions
  • Reading and writing via value proxy

Was this helpful?

Export as PDF
  1. Form

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';

You can't reasign value proeprty itself only nested properties can be read and set.

Wrong usage:

form.value = { user: { email: 'example@example.com' } }

PreviousValue OptionsNextEvents

Last updated 4 years ago

Was this helpful?