为了使用提交按钮对门户的最后一页进行评估,微软为提交按钮应触发的函数"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
按下submit按钮应该会触发"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;
}我的研究表明,其他人只是粘贴了相同的代码。Witch告诉我,它应该以某种方式工作: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
发布于 2018-12-27 00:43:52
如果使用的是实体表单,请使用entityFormClientValidate代替webFormClientValidate
https://stackoverflow.com/questions/50943212
复制相似问题