Discussions

Expand all | Collapse all

Don't save the record if the function returns false otherwise save the record

  • 1.  Don't save the record if the function returns false otherwise save the record

    Posted 08-31-2017 12:15

    I have a child function alertMSGS so the alertMSGS function checks the values in four variables and gives a alert message that they are not equal, so it will return false to the parent function which is DoSave() its a closure function , from my knowledge . So if the return is false i need to exit the save otherwise need to perform the save. !! See below . Many Thanks in advance

    function alertMSGS(){  <br>   var currentWeekEarning = parseFloat( $("#_fid_19").val() );      var totalYearEarning= parseFloat( $("label[for=_fid_39]").next("div").text().replace('$', '').replace(',', '') );        var currentLoss = parseFloat($("#_fid_20").val());        var totalYearLoss= parseFloat($("label[for=_fid_38]").next("div").text().replace('$', '').replace(',', '') )        if( (currentWeekEarning != totalYearEarning) ){          alert("currentWeekEarning  Not Equal to totalYearEarning");          return false;          }        if ( currentLoss != totalYearLoss) {          alert(' currentLoss Not Equal to totalYearLoss');          return false;        }      }          DoSave = (function(fn){        return function(){        var resultofalertMSGS = alertMSGS();        if (resultofalertMSGS === false) {         // so if the function returns  false then  i need to exit from the (DoSave Function) and if it satisfies then i need to perform the (DoSave Function)        }          var result=fn.apply(fn, arguments);          return result;        };  })(DoSave);


    I got the DoSave() function code from quickbase itself , so i hope i will get a reply on this. 


  • 2.  RE: Don't save the record if the function returns false otherwise save the record

    Posted 09-07-2017 09:43
    I got the solution. i hope this will help anyone 


    DoSave = (function(fn){       return function(){       var resultofalertMSGS = alertMSGS();       if (resultofalertMSGS === false) {         return false;         }else{         var result=fn.apply(fn, arguments);         return result;       } } })(DoSave);