Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to cancel Submit process once i clicked the button? Overriding the default logic

(0) ShareShare
ReportReport
Posted on by 150

Hello everyone,

I am just starting with microsoft portals, i created a Entity Form and a Web Page realated to that Entity Form.

I added a submit action button to the Entity Form and i added my custom javascript to the Web Page.

The scenario is create new account records in CRM through the portal, and if the email address is empty, do not create the record.

To make the field required is not a solution for my future business logic.

I made this javascript trying to interrupt the submitting if the email address is empty:

$(document).ready(function() {
$('#InsertButton').on('click', function (e) {
e.preventDefault();
alert("button was clicked");
var emailAddress = $('#emailaddress1').val();
if(emailAddress === null || emailAddress === ""){
alert("Please provide an email");
}
alert(emailAddress);
})
});

By any reason, the submitting keeps going on, even if see the pop-up "Please provide an email"

I already tried to use:

return false

return

$("form").onsubmit(return false;)

I also tried  the page validator: https://community.adxstudio.com/products/adxstudio-portals/documentation/configuration-guide/web-forms/web-form-steps/custom-javascript/ but is not longer working since version update.

And my last approach is using the preventDefault(); but still cannot cancel the submitting process and cannot override the onclick  submit button functionality

Does someone know how could I override the functionality on click submit button?

Thanks very much in advance!

*This post is locked for comments

  • Jorge Gomez Profile Picture
    Jorge Gomez 150 on at
    RE: How to cancel Submit process once i clicked the button? Overriding the default logic

    Wow, I just tried the page validator out of the button click event and it works...

    Well, thanks very much Birgit RD

  • Jorge Gomez Profile Picture
    Jorge Gomez 150 on at
    RE: How to cancel Submit process once i clicked the button? Overriding the default logic

    By the way yes, I found in Form Options / Additional Settings / Enable Validation Summary Links. Yes it is checked.

  • Jorge Gomez Profile Picture
    Jorge Gomez 150 on at
    RE: How to cancel Submit process once i clicked the button? Overriding the default logic

    Hello Birgit RD,

    Thanks very much for your help and your comments, I really appreciate them because I was feeling completly stuck.

    I just went to CRM to the Entity Form, but I cannot see any "Enable Validation Summary Links" in the additional settings.

    The page validator is inside the onclick event of a button, since i thought I want to check if the Email has been filled once i click the submit button, but maybe I am wrong on my approach

    How do you think it should be done?

    Thanks in advance!

  • Verified answer
    Birgit RD Profile Picture
    Birgit RD 2 on at
    RE: How to cancel Submit process once i clicked the button? Overriding the default logic

    On the entity form, do you have the "Enable Validation Summary Links" checked in the additional settings?

    Secondly, that page validator is inside the onclick event of a button? I see $('#InsertButton').on('click', function () {

      alert("button has been clicked");

    Should this not be closed by )};?

  • Jorge Gomez Profile Picture
    Jorge Gomez 150 on at
    RE: How to cancel Submit process once i clicked the button? Overriding the default logic

    Hello again Birgit RD,

    I tried to reproduce your code adjusted to my scenario:

    if(window.jQuery){

    alert("jQuery exist");

    (function($) {

    $(document).ready(function() {

      $('#InsertButton').on('click', function () {

      alert("button has been clicked");

      if (typeof (Page_Validators) == 'undefined') return;

    alert("Page_Validators is defined");

      // Create new validator

      var newValidator = document.createElement('span');

      newValidator.style.display = "none";

      newValidator.id = "emailaddress1Validator";

      newValidator.controltovalidate = "emailaddress1";

      newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form

      newValidator.initialvalue = "";

      newValidator.evaluationfunction = function () {              

      var retVal = true;

      newValidator.errormessage = "";

      var emailAddress = $('#emailaddress1').val();

      if(emailAddress === null || emailAddress === ""){

      alert("email is empty");

    newValidator.errormessage = "Use must introduce a valid email address.";

    retVal = false;

      }

      alert("evaluation finished");

      return retVal;

      };

      // Add the new validator to the page validators array:

      Page_Validators.push(newValidator);

     })

    });

    }(window.jQuery));

    }

    My browser gives me the alerts "jQuery exist", "Page_Validators is defined" and then the record is submitted.

    I ensure the email field is empty, and i dont even receive the alert "evaluation finished"

    Just for the record, in your code:

    newValidator.id = "commentvalidator";   => you are adding this id name in the code randomly right? there is not any CRM relation

              newValidator.controltovalidate = "feb_password";  => this feb_password is your CRM field name or its the id of the element on the HTML code?

    thanks in advance!

  • Jorge Gomez Profile Picture
    Jorge Gomez 150 on at
    RE: How to cancel Submit process once i clicked the button? Overriding the default logic

    Yes, i checked i passed the first condition, in any case, thanks very much for your posts, i will try again the page validator with your approach, you gave me a clue

  • Birgit RD Profile Picture
    Birgit RD 2 on at
    RE: How to cancel Submit process once i clicked the button? Overriding the default logic

    Did you check, you passes the first condition (if (typeof (Page_Validators) == 'undefined'))?

    In one case, I had the issue that Page_Validators where undefined.

    This is more or less what we use (in our case we have multiple languages implemented)

    var validatorCounter = 0;

    //Add Page Validator

    if (window.jQuery) {

       (function ($) {

           $(document).ready(function () {

               if (typeof (Page_Validators) == 'undefined') return;

               // Create new validator

               var newValidator = document.createElement('span');

               newValidator.style.display = "none";

               newValidator.id = "commentvalidator";

               newValidator.controltovalidate = "feb_password";

               newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form

               newValidator.initialvalue = "";

               newValidator.evaluationfunction = function () {

                   validatorCounter++;

                   var errors = [];                

                   var retVal = false;

                   if (validatorCounter == 2) {

                       validatorCounter = 0;

                       retVal = true;

                       var err = "";

                       newValidator.errormessage = "";

                       //check password(confirm) filled ans both same

                       var pwd= $("#feb_password").val();

       var pwdc = $("#feb_passwordconfirm").val();

                       if (pwd != pwdc) {

                                newValidator.errormessage = "Password and Confirm Password have to be the same.";

                                retVal = false;

                       }

                   }

                   return retVal;

               };

               // Add the new validator to the page validators array:

               Page_Validators.push(newValidator);

           });

       }(window.jQuery));

    }

    The counter is put in place because the validator was executed multiple times.

  • Jorge Gomez Profile Picture
    Jorge Gomez 150 on at
    RE: How to cancel Submit process once i clicked the button? Overriding the default logic

    Hello Birgit RD could you explain with a bit more of detail how did you use the page validator?

    Since i tried to implement it, and  the return false didnt stop the submitting.

    if (typeof (Page_Validators) == 'undefined') return;

            // Create new validator

            var newValidator = document.createElement('span');

            newValidator.style.display = "none";

            newValidator.id = "emailaddress1Validator";

            newValidator.controltovalidate = "emailaddress1";

            newValidator.errormessage = "<a href='#emailaddress1_label'>Email is a required field.</a>";

            newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form

            newValidator.initialvalue = "";

            newValidator.evaluationfunction = function () {

               var contactMethod = $("#preferredcontactmethodcode").val();

               if (contactMethod != 2) return true; // check if contact method is not 'Email'.

               // only require email address if preferred contact method is email.

               var value = $("#emailaddress1").val();

               if (value == null || value == "") {

               return false;

               } else {

                  return true;

               }

            };

  • Birgit RD Profile Picture
    Birgit RD 2 on at
    RE: How to cancel Submit process once i clicked the button? Overriding the default logic

    We are on the latest version of online portals.

    Page validators do work for us. No submit happens.

    What did change (but not with our latest upgrade) was that after the validator shows the error message, it refreshes the page and re-executes the onload javascript code. This did mess up some of our java code.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,387 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans