In this guide, we will explain how to record previous input values for the next form entries.
We will get the current field value on the form by the previous input recorded values.
Drag and drop some fields with a JavaScript field as shown below.
Click the pencil icon of the JavaScript field and paste the code.
Please use the code below:
// Array of field IDs
var field_ids = [ 'b5d2-641a-0ce6', '2758-878b-1fe6', 'e816-0a0d-9322' ];
// Loop through each field ID in the array
for ( var field_id of field_ids ) {
// Attach an input event listener to the component with the corresponding
window.formyoula.form_fields[ field_id ].on( 'all', function( options ) {
// Check if the value is not null
if ( this.get( 'value' ) ) {
// Save the current value of the field to local storage with a key
localStorage[ 'formyoula_saved_field_value_' + this.get( 'component_id' ) ] = this.get( 'value' );
}
} );
// Check if a value is saved in local storage for a specific field ID
if ( localStorage[ 'formyoula_saved_field_value_' + field_id ] ) {
// Set the value of the field to the saved value in local storage
window.formyoula.form_fields[ field_id ].set( { value: localStorage[ 'formyoula_saved_field_value_' + field_id ] } );
}
}
Change the field IDs according to your form. Save the changes.
Try the form. Input some values and submit the form. It will record input values for the next form entries.
Try the form again. It will show the recorded field's value.
For any questions, please contact us - [email protected] or the Formyoula in-app chat 🙂
Example Form.json4.0KB