Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Section
Column

Customizing can be done in several different ways. It is important to consider all the alternatives available when deciding on a method to accomplish form customization.

Warning

Although JavaScript will accomplish the task, it is important to note that your scripts are not subjected to formal testing by the frevvo quality assurance team. Choosing an approach that is part of the product like Business Rules is a better choice than adding JavaScript since released versions undergo rigorous quality assurance testing. Customizations using JavaScript should only be used under special situations and if there is no other way to customize the form to the requirements.

For example, let's say you have a message control in your form that contains markup to pull a custom JavaScript. The URL for the script contains the home directory and revision number - (http://localhost:8080/frevvo/js-24487/libs/script.js).  An upgrade of  to new release or revision version could potentially stop the form from working.

If you choose to add JavaScript, we strongly recommend that you are familiar with a JavaScript debugger / web development tool such as the Firebug extension for Firefox.

Here  are some real world situations where custom JavaScript can be used in a form. The custom JavaScript can be added to the form using the message control or the include.js file in the frevvo.war. Refer to Customizing Behavior for more information.

Column
width240px

On This Page:

Table of Contents
maxLevel1

...

Add CorrectCase to the CSS Class property of the control to enable this JavaScript.  

Limit selection of checkbox options

The JavaScript below will limit the choices to a maximum of three for a checkbox control in a form. Add limit3 to the CSS Class property of that control to enable this JavaScript.  

Code Block
var CustomEventHandlers = {
   setup: function (el) {
       if (CustomView.hasClass(el, 'limit3')) {
           FEvent.observe(el, 'click', this.checkboxlimit.bindAsObserver(this, el));
       }
   },
   checkboxlimit: function (evt, el) {
       var checkgroup = el.childrenWithClassName('input');
       var limit = 3;
       for (var i = 0; i < checkgroup.length; i++) {
           checkgroup[i].onclick = function () {
               var checkedcount = 0
               for (var i = 0; i < checkgroup.length; i++)
               checkedcount += (checkgroup[i].checked) ? 1 : 0
               if (checkedcount > limit) {
                   this.checked = false
                   for (var i = 0; i < checkgroup.length; i++)
                   (checkgroup[i].checked) ? checkgroup[i].disabled = false : checkgroup[i].disabled = true;
               } else {
                   for (var i = 0; i < checkgroup.length; i++)
                   checkgroup[i].disabled = false;
               }
           }
       }
   }
}

.  

Scroll to Top

A Tab control with many fields in each tab, may require a long scroll to switch from one tab to another. You can use a trigger control at the bottom of the first tab with a business rule to navigate the user to the second tab when the trigger is clicked. For example, when you click on the Next Tab trigger control on the Personal Information tab in the Application for Employment form shown a business rule will navigate the user to the Employment History tab. 

...

Code Block
var CustomEventHandlers = {
   uploadEl: null,
   setup: function (el) {
       if (CustomView.hasClass(el, 'onlyPDF')) {
           this.uploadEl = el;
       }
       window.setTimeout('CustomEventHandlers.checkFile()', 3000); // set the initial timer
   },
   checkFile: function () {
       for (var i = 0; i < this.uploadEl.parentNode.childrenWithClassName('f-file-upload-file-name').length; i++) {
           if (!(/^.*\.(pdf|PDF)$/.test(this.uploadEl.parentNode.childrenWithClassName('f-file-upload-file-name')[i].getAttribute('title')))) {
               alert("Invalid file '" + this.uploadEl.parentNode.childrenWithClassName('f-file-upload-file-name')[i].getAttribute('title') + "' will be removed.");
               this.uploadEl.parentNode.childrenWithClassName('f-upload-file-list-delete')[i].click();
           }
       }
       window.setTimeout('CustomEventHandlers.checkFile()', 3000);
   }
}

 

Automatically submit a form

...

Tip

 Users expect the submit and cancel buttons to be located at the bottom of a form. Moving the location of the Submit control is not recommended.

...

Submit on Enter Key Press

...

This custom JavaScript automatically inserts dashes as the user enters a phone number into a Phone control. Characters other than the dash entered into the control are deleted. Add PhoneInsert to the CSS Class property of the Phone control to enable this JavaScript. 

Code Block
languagejavascript
var CustomEventHandlers = {

      setup: function (el) {
 
         if (CustomView.hasClass(el, 'PhoneInsert')) {
  
            FEvent.observe(el, 'keydown', this.formatPHONE.bindAsObserver(this, el));

              FEvent.observe(el, 'keyup', this.formatPHONE.bindAsObserver(this, el));
  
        }
    },
   }, formatPHONE: function (event, element) {
           if (event.keyCode != 46 && event.keyCode != 8) {
 
             fldVal = $(element).value;
               var nom = fldVal.charAt(fldVal.length - 1);
               if (isNaN(nom) && nom != "-") {
  
                $(element).value = fldVal.substring(0, fldVal.length - 1);
               } else {
 
                 if ((fldVal.length == 3) || (fldVal.length == 7)) {
  
                    $(element).value = fldVal + "-";

                  }
                   if (fldVal.length > 12) {
                       $(element).value = fldVal.substring(0, fldVal.length - 1);
 
                 }
               }
           }
       }
  
}