Versions Compared

Key

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

...

' Quantity control allows only whole numbers. An error message will display if a number with a  decimal point value is entered. The forms designer can restrict users from entering a value with a decimal point using this JavaScript. This script will automatically remove a decimal point from the field and the error message will not display.  Similar logic can be used to implement instant validation on other control types as well.

Code Block
var CustomEventHandlers = {
        setup: function (el) {
            if (CustomView.hasClass(el, 'onlyDigits')) {
                FEvent.observe(el, 'keydown', this.allowOnlyDigits.bindAsObserver(this, el));
                FEvent.observe(el, 'keyup', this.allowOnlyDigits.bindAsObserver(this, el));
            }
        },
        allowOnlyDigits: function (event, element) {
            fldVal = $(element).value;
            for (var i = 0; i < fldVal.length; i++) {
                var nom = fldVal.charAt(i);
                if (isNaN(nom)) {
                    $(element).value = fldVal.substring(0, i) + fldVal.substring(i + 1, fldVal.length);
                }
            }
        }
    }
 

Add onlyDigits in the CSS Class property of the Quantity control. This script will automatically remove a decimal point from the field and the error message will not display.  Similar logic can be used to implement instant validation on other control types as well.