1
votes

Is there is some way to apply mask on fields in crm 2013 on forms, using any jQuery and jQuery mask plugins.

I read from http://taoofcrm.com/2011/05/19/crm-field-masking-with-jquery/ but it not worked for me on Dynamic crm 2013.

1

1 Answers

3
votes

In crm 2011 input field ID is the name of attribute, while in crm 2013 input field ID is the name of attribute plus "_i" (may be "i" denote an input).

So if we have attribute name "name" then input field ID for this attribute in 2011 is "name" and in 2013 it is "name_i".

Following is the Source view of input field of an attribute on the form in crm 2011 and crm 2013.

Input field in crm 2011

 <input id="name" tabindex="1010" class="ms-crm-Input ms-crm-Text" style="-ms-ime-mode: auto;" type="text" maxlength="255" value="test" attrformat="text" attrpriv="7" attrname="name" req="2">

Input field in crm 2013

<input id="name_i" title="" class="ms-crm-InlineInput" aria-labelledby="name_c name_w" style="-ms-ime-mode: active;" type="text" maxlength="160" attrname="name" attrpriv="7" controlmode="normal" defaultvalue="Blue Yonder Airlines (sample)">

If you applying masking in crm 2011, then please see here!, or just use following code.

//Include jquery and jqueryMask plugin file on form you apply masking.
function Mask(field, format)
{ 
$("#"+field).mask(format);
}

// call this function on form load event 
function maskFields()
{
Mask("address1_postalcode", "99999-9999");
Mask("telephone1", "(999) 999-9999");
Mask("telephone2", "(999) 999-9999");
Mask("fax", "(999) 999-9999");

}

For crm 2013 you should attach "_i" with field name like.

function Mask(field, format)
{ 
$("#"+field+"_i").mask(format);
}

But also still not working because in crm 2013 input fields are created on execution time. you should apply masking on click event of input, or just got focus of attribute before apply masking e.g.

//Include jquery and jqueryMask plugin file on form you apply masking.
function Mask(field, format) {
  //first check whether attribute exist or not
    var oCtrl = Xrm.Page.getControl(field);
    if (oCtrl != null) {

        oCtrl.setFocus(true);
        $("#" + field + "_i").mask(format);
    }
} 

// call this function on form load event 
function maskFields()
{
Mask("address1_postalcode", "99999-9999");
Mask("telephone1", "(999) 999-9999");
Mask("telephone2", "(999) 999-9999");
Mask("fax", "(999) 999-9999");

}

Worked well for crm 2013.