How to apply masking in Dynamic crm 2013

Deadly 提交于 2020-01-06 03:03:47

问题


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:


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.



来源:https://stackoverflow.com/questions/21525883/how-to-apply-masking-in-dynamic-crm-2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!