2

To make an evaluation on the last page of a portal, using the submit button, Microsoft provides an extension for the function "webFormClientValidate" that the submit button should trigger: https://learn.microsoft.com/en-us/dynamics365/customer-engagement/portals/add-custom-javascript.

I put this code in my last step in the portal:

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

On pageload the log writes out: alive 1 2 3 4

Pressing the submit button should trigger the "webFormClientValidate" function, but nothing happens. "5" is not being written to the log. Anyone know why?

Update: From debugging it appears as if the page does not recognize "webFormClientValidate" at all. Searching through the elements however, this guy appears:

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

My research shows other people just pasting in the same bit of code. Witch tells me that it should work somehow: 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

ToFo
  • 1,643
  • 1
  • 19
  • 34
  • Fyi; https://community.adxstudio.com/products/adxstudio-portals/documentation/configuration-guide/web-forms/web-form-steps/custom-javascript/ – James Wood Jun 20 '18 at 20:21
  • Are you sure `webFormClientValidate` gets called without any of your customisations? – James Wood Jun 20 '18 at 20:23
  • If I do a right click -> inspect directly on the submit button I can see that it is linked to webFormClientValidate, as described in the documentation. But no I am not sure at all, since it is not working – ToFo Jun 21 '18 at 05:32
  • 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 = '......... – ToFo Jun 21 '18 at 05:36

1 Answers1

4

If you are using an Entity Form, use entityFormClientValidate in place of webFormClientValidate

BillV
  • 61
  • 5