CRM Dynamics 2013 JavaScript验证自由文本字段中的最小字符

时间:2016-03-31 08:26:03

标签: javascript dynamics-crm-2013

我有一个简单的验证,我需要在表单上执行它强制用户在字段中具有最少量的字符,我有以下代码如下,但它不起作用,我试过它加载和保存活动但没有运气,请协助。

function TemsAndCondtitionsValidation()
{
 var TermsandCon = Xrm.Page.getAttribute("new_termsconditions").getValue();
 if(TermsandCon.value.length < 140)
  {
    Xrm.Utility.alertDialog("The length of characters entered are less than the minimum requirement of 140 characters");
  }

}

2 个答案:

答案 0 :(得分:0)

如果new_termsconditions是文字类型(单行或多行),您只需修改代码即可:

if(TermsandCon.length < 140)

答案 1 :(得分:0)

使用表单编辑器将此功能附加到onsave事件:

function TemsAndCondtitionsValidation(context)
{
    var termsConds = Xrm.Page.getAttribute("new_termsconditions").getValue();
    if(termsConds.length < 140)   {
        Xrm.Utility.alertDialog("The length of characters entered are less than the minimum requirement of 140 characters");
        context.getEventArgs().preventDefault(); // cancel save
    }
}