Set End Date Field One Hour Ahead Of Start Date

This guide will explain how to set the date field one hour ahead.

We will use two Date Time fields and get value from the user in the first field, and the second field will auto-set the value one hour ahead.

Drag and drop two Date Time fields and a JavaScript field. Rename the Date Time fields as shown below.

image

Click the pencil icon of the JavaScript field and paste the code. Save the changes.

image

Please use the code below:

// Listen to Formyoula field changes based on Id or label
window.formyoula.form_fields[ 'Start Date' ].on( 'all', function() {
  // Increment time for an hour
  var one_hour_later = moment( this.get( 'value' ) ).add( 1, 'hours' );
  // Set the new field value
  window.formyoula.form_fields[ 'End Date' ].set( { value: one_hour_later } );
} );

Try the form. When a user sets the date and time in the ā€œStart Dateā€ field, the form auto-sets the one-hour later time in the ā€œEnd Dateā€ field.

image

Optional: You can hide the second Date Time field labelled ā€œEnd Dateā€ on the form.

Drag and drop a Field Update Workflow field. Set Field Updates to hide the ā€œEnd Dateā€ field:

End Date || hidden || true

Save the changes.

image

Try the form. It will hide the field labelled ā€œEnd Dateā€.

image

For any questions, please contact us - [email protected] or the Formyoula in-app chat šŸ™‚