This project is read-only.

Project Description


NOTE: THIS IS UNSUPPORTED CRM 2013 CUSTOMIZATION.

To provide masking for input fields in CRM form we can use jQuery masked input plugin.

 Using this plugin we can easily add masking for not only phone number, fax, date fields but also we can add masking for like SSN number, driving license number etc.

Also when adding this masking, this plugin is already taking care of inputs validation like phone number should contain only numbers.

 We can add our own formats also using this plugin. For more details about this plugin, Check  http://digitalbush.com/projects/masked-input-plugin/

For CRM implementation


 

var CustomMaskScript = {

    MaskInputField: function (fieldName, format) {       

        var control = Xrm.Page.getControl(fieldName);

        if (control != null && control.getControlType() == 'standard') {

            control.setFocus();

            if (Xrm.Page.getAttribute(fieldName).getAttributeType() == 'datetime') {

                var input = $("#" + fieldName + "_i").find("input");

                if (input != null)

                    input.mask(format);

            } else

                $("#" + fieldName + "_i").mask(format);

        }

    },

};

 


 

  •          Now add both file in entity form library where you want to use masking
  •          Call MaskInputField function on load of Form with attribute name and Format as parameters. 'new_birthdate','99/99/9999'

  • Save and publish customization.
  • And maked input is ready to use

 


 

To Add masking for all phone number and date attributes on form, add following code in JS web resource, add web resource in form library and call function. 

var DefaultMask = {

    MASK_date: '99/99/9999',

    MASK_Phone: '(999) 999-9999',

     MaskDatePhoneInput: function () {

        var PageAttributes = Xrm.Page.data.entity.attributes.get();

        var fieldName = '';

        var Format = '';

        for (var i in PageAttributes) {

            var control = PageAttributes[i].controls.get(0);

            fieldName = PageAttributes[i].getName();

            Format = PageAttributes[i].getFormat();

            if (Format == 'phone' || Format == 'date') {

                control.setFocus();

                if (PageAttributes[i].getAttributeType() == 'datetime') {

                    var input = $("#" + fieldName + "_i").find("input");

                    if (input != null)

                        input.mask(ContactDefaultMask.MASK_date);

                } else

                    $("#" + fieldName + "_i").mask(ContactDefaultMask.MASK_Phone);

            }

        }

    },

}

 

 


Some examples of Masking

  • Date (Masking Format : 99/99/9999)

  • Phone Number (Masking Format : (999) 999-9999)

  • Phone Number with Extension (Masking Format : (999) 999-9999?X9999)

  • Social Security Number (Masking Format: 999-99-9999)

  •          Custom (e.g. Wisconsin Driving license) (Masking Format: a-9999999999)

Last edited Jun 11, 2014 at 9:41 PM by mahadeomatre, version 2