The simplest way to gather data from a user is to use Fliplet’s form component. Once you’ve dragged and dropped one on to a screen you can reference it with JavaScript in the Developer Options. The example below gets the first form component it finds on the screen (if there are multiple forms you will need to specify a form name to ensure you get the correct one).
It then looks for a field with the name ’email’. This name can be anything you want but it has to match a field name that you’ve used in your form component.
Once you have the field you can get the field’s value with the .get()
method.
Fliplet.FormBuilder.get() .then(function (form) { // Get the field with name 'email' var field = form.field('email'); // gets the input value var value = field.get(); });
You may want to set the data in a form field for a user. This is typically done to save the user time if you already know the answer. For example if you know the user that logged in to the app you can pre-populate the email address field for them so they don’t have to type it in.
The following code sets the ’email’ field value to ‘hello@fliplet.com’:
Fliplet.FormBuilder.get() .then(function (form) { // Get the field with name 'email' var field = form.field('email'); // sets the input value var value = field.set('hello@fliplet.com'); });