【问题标题】:How to trigger webFormClientValidate in Dynamics 365 Portals如何在 Dynamics 365 门户中触发 webFormClientValidate
【发布时间】:2018-06-20 08:01:37
【问题描述】:

为了对门户的最后一页进行评估,使用提交按钮,Microsoft 为提交按钮应触发的函数“webFormClientValidate”提供了扩展: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/portals/add-custom-javascript.

我把这段代码放在了门户的最后一步:

console.log("alive");

if (window.jQuery) {
console.log("1");

    (function ($) {
        console.log("2");
        if (typeof (webFormClientValidate) != 'undefined') {
            console.log("3");
            var originalValidationFunction = webFormClientValidate;
            if (originalValidationFunction && typeof (originalValidationFunction) == "function") 
            {
                console.log("4");
                webFormClientValidate = function() 
                {
                    console.log("5");
                    originalValidationFunction.apply(this, arguments);
                    console.log("6");
                    // do your custom validation here

                    if (...) 
                    {
                        console.log("7 false");
                        return false;
                    }
                    // return false; 
                    // to prevent the form submit you need to return false
                    // end custom validation.

                    return true;
                };
            }
        }
    }(window.jQuery));
}

在页面加载时,日志会写出: 活 1 2 3 4

按下提交按钮应该会触发“webFormClientValidate”功能,但什么也没有发生。 “5”未写入日志。有人知道为什么吗?

更新:从调试来看,页面似乎根本无法识别“webFormClientValidate”。然而,通过元素搜索,这个人出现了:

function webFormClientValidate() {
                            // Custom client side validation. Method is 
called by the next/submit button's onclick event.
                            // Must return true or false. Returning false 
will prevent the form from submitting.
                            return true;
                        }

我的研究表明,其他人只是粘贴了相同的代码。女巫告诉我它应该以某种方式工作: http://threads290.rssing.com/chan-5815789/all_p2645.html https://rajeevpentyala.com/2016/09/12/useful-jscript-syntaxes-adx-portal/ http://livingindynamics365.blogspot.com/2018/02/validating-user-input-in-crm-portals.html

【问题讨论】:

  • 你确定webFormClientValidate 在没有任何自定义的情况下被调用吗?
  • 如果我右键单击 -> 直接在提交按钮上检查,我可以看到它链接到 webFormClientValidate,如文档中所述。但不,我完全不确定,因为它不起作用
  • onClick=javascript:if(typeof webFormClientValidate === 'function'){if(webFormClientValidate()){if(typeof Page_ClientValidate === 'function'){if(Page_ClientValidate('') ){clearIsDirty();disableButtons();this.value = 'Processing...';}}else{clearIsDirty();disableButtons();this.value = 'Processing...';}}else{return false ;}}else{if(typeof Page_ClientValidate === 'function'){if(Page_ClientValidate('')){clearIsDirty();disableButtons();this.value = '.........跨度>

标签: javascript dynamics-crm microsoft-dynamics adxstudio-portals dynamics-crm-portals


【解决方案1】:

如果您使用的是实体表单,请使用 entityFormClientValidate 代替 webFormClientValidate

【讨论】:

    猜你喜欢
    • 2021-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多