iFormBuilder JavaScript Tips & Tricks
What's covered:
- What is Page Level JavaScript?
- How do I change the format of a date?
- How do I change the format of the Time Zone?
What is Page Level JavaScript?
Page Level JavaScript loads user-defined global variables and functions that can be called by a parent form and/or any of the related child forms.
Click here for more information on Page Level JavaScript.
How do I change the format of a date?
To change the format of a date captured by iFormBuilder, please follow the instructions below.
PLEASE NOTE: In the example below we will be changing the format to YYYYMMDD.
STEP 1. From inside your form, click the Page Level JavaScript icon.
STEP 2. Paste in the following JavaScript:
Date.prototype.yyyymmdd = function() {
var yyyy = this.getFullYear().toString();
var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
var dd = this.getDate().toString();
return yyyy + (mm[1]?mm:"0"+mm[0]) + (dd[1]?dd:"0"+dd[0]); // padding
};
d = new Date();
STEP 3. Click Save and then Close.
STEP 4. Add a Text element to your form.
PLEASE NOTE: You can use the Read-Only element as well. Do NOT use the Date element.
STEP 5. In the Dynamic Value field of the element, place the following:
d.yyyymmdd()
STEP 6. Save your form.
STEP 7. Test out the functionality on your form.
PLEASE NOTE: If you want to change the format of the order, update the order in this portion of the Page Level JavaScript: "return (mm[1]?mm:"0"+mm[0]) + (dd[1]?dd:"0"+dd[0]) + yyyy; // padding"
How do I change the format of the time zone?
iOS 16 changes the date-time stamp produced from the date object and writes out the time zone name instead of an abbreviation. If you are using an integration that relies on a specific format, such as the time zone being abbreviated, you can use the Page Level Javascript below to convert the format to an abbreviation.
function getNormalDate(d) {
var d = Date();
var result;
// Handle eastern time
if (d.indexOf("Eastern Daylight Time") >-1 ){
result = d.replace("Eastern Daylight Time","EDT");
}
else if (d.indexOf("Eastern Standard Time")>-1){
result = d.replace("Eastern Standard Time","EST");
}
// Handle central time
else if (d.indexOf("Central Daylight Time")>-1){
result = d.replace("Central Daylight Time","CDT");
}
else if (d.indexOf("Central Standard Time")>-1){
result = d.replace("Central Standard Time","CST");
}
// Handle mountain time
else if (d.indexOf("Mountain Daylight Time")>-1){
result = d.replace("Mountain Daylight Time","MDT");
}
else if (d.indexOf("Mountain Standard Time")>-1){
result = d.replace("Mountain Standard Time","MST");
}
//Handle pacific time
else if (d.indexOf("Pacific Daylight Time")>-1){
result = d.replace("Pacific Daylight Time","PDT");
}
else if (d.indexOf("Pacific Standard Time")>-1){
result = d.replace("Pacific Standard Time","PST");
}
return result;
}
Update the field that is populating the date to the following Dynamic Value:
getNormalDate(element_name)
Comments
0 comments
Please sign in to leave a comment.