JavaScript Tips and Tricks
Table of Contents
What is the Date Element?
The Date Element allows users to capture the past, present, or future date stored in a localized format. In the U.S., the date will appear as Month-Day-Year.
Click here for more information on the Date Element.
What are Dynamic Values?
Dynamic Values are JavaScript statements used to apply a value to an element based on specific conditions.
Click here for more information on Dynamic Values.
How do I dynamically populate the Date Element?
To dynamically set the date of an element based on the current date, please follow the instructions below. In this example, we will show you how to add 90 days to the current date.
PLEASE NOTE: This will only work on iOS.
How do I dynamically populate the date?
STEP 1. Add a Date Element to your form with a data column name of date1.
STEP 2. Under the Smart Control tab, in the Dynamic Value field, type in the following: new Date().
This tells the element to default to the current date when the record is created.
STEP 3. Create another Date Element with a data column name of date2.
STEP 4. In the Dynamic Value of the date2 element, put the following:
new Date(date1.getFullYear(), date1.getMonth(), date1.getDate() +90)
This will tell the element to add 90 days to the date in the date1 element.
STEP 5. Test the functionality on your iOS device.
iFORM TIP: In the condition value of the date1 element, put false.
This will hide the element from the user so no data can be altered.
Download this form package to use as an example.
Comments
1 comment
Could a function like this be used instead of creating the extra widget?
function someDate() {
var now = new Date();
return new Date(now.getFullYear(), now.getMonth(), now.getDate()+90);
}
Please sign in to leave a comment.