AnsweredAssumed Answered

AJAX Javascript validation on save click - save does not occur

Question asked by Richard Coleman on Jul 15, 2015
Latest reply on Jul 16, 2015 by Richard Coleman
Using 6.5.8 enterprise, and using this as reference:

I've started by including the underscoreJS library, and my external file:

3 => 
        array (
          'file' => 'custom/modules/Accounts/js/vatCheck.js',          ),

So I have a javascript file which goes to a PHP file and returns a JSON object which I validate,and popup a message box if wrong, and return false.

Everything is working fine, my console.log statements are working. Everything is fine up until the point I re-validate.

If there is a Sugar validation issue, it flags it. However, if there are no issues, it should return true, and save. However, no action is taken if everything validates.

SUGAR.util.doWhen("typeof(check_form) != 'undefined' && typeof check_form == 'function'", function() {      check_form = _.wrap(check_form, function(originalCheckFormFunction, originalCheckFormFunctionArg) {          // Adding custom validation           //isCustomValid = confirm('Are you sure you want to save this record?');          var isCustomValid;    var vatRegNumber = document.getElementById('vat_reg_number_c').value;          var countryCodeField = document.getElementById('country_code_c');  var countryCodeValue = countryCodeField.options[countryCodeField.selectedIndex].value;     console.log("Preparing the Ajax Call");      var ajaxCall = new XMLHttpRequest();          ajaxCall.onreadystatechange = function()    {           if (ajaxCall.readyState == 4 && ajaxCall.status == 200)     {     if (ajaxCall.responseText.length > 0)     {      var data = JSON.parse(ajaxCall.responseText);      console.log(data);      if (data.success == 1)      {       console.log("Result succeeded");       vatRegNumber.value = data.code;       console.log("The verification returned: ".concat(originalCheckFormFunction(originalCheckFormFunctionArg)));       return originalCheckFormFunction(originalCheckFormFunctionArg);      }      else      {       console.log("Result failed");{msg: data.error, title: 'Error:'} );       return false;      }     }    }   }"GET", "" + vatRegNumber + "&countryCode=" + countryCodeValue, true);   console.log("Making the call");   ajaxCall.send();            });  });

Am I missing a separate call, or do I need to return a different value? Any ideas what I might be missing? Thanks for reading!