繁体   English   中英

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是text类型(单行或多行),则可以像下面这样简单地修复代码:

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
    }
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM