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

CRM Dynamics 2013 JavaScript Validate Minimum characters in free text field

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

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");
  }

}

如果 new_termsconditions 是文本类型(单行或多行),您可以像这样简单地修改您的代码:

if(TermsandCon.length < 140)

使用表单编辑器将此函数附加到您的 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
    }
}