xsanisty / calx.js

jQuery Calx - a jQuery plugin for creating formula-based calculation form
http://www.xsanisty.com/project/calx2
MIT License
198 stars 72 forks source link

Getting too many Maximum call stack size exceeded errors in cell.fx.processDependency #40

Closed MB34 closed 7 years ago

MB34 commented 7 years ago

This is not that complicated a form. Can't understand why this is happening Fiddle: https://jsfiddle.net/Mrbaseball34/dtbygwpb/

It also clears the value entered into the field. Try putting value in ECI Amount field then tab out.

What am I doing wrong?

ikhsan017 commented 7 years ago

For the ECI amount, it has data-formula attribute, so direct input to it is prohibited

it get max call stack exceeded because there are circular reference in your calculator, try enable circular reference check

$('#form').calx({checkCircularReference:true});

and it will alert

Circular reference detected, this may cause calx to stop working.
cell : E47
formula : IF(ISERROR(E15/E48),"", ROUND(E15/E48,4))

Please check each cells involved in the formula that has direct or indirect reference to E47
ikhsan017 commented 7 years ago

I have wrote simple explanation about it here http://www.xsanisty.com/handling-maximum-call-stack-size-exceeded-in-jquery-calx/

MB34 commented 7 years ago

For some reason, I can't access your website:

Request URL:http://www.xsanisty.com/handling-maximum-call-stack-size-exceeded-in-jquery-calx/ Request Method:GET Status Code:403 Forbidden Remote Address:31.220.105.114:80 Response Headers view source Cache-Control:max-age=3600, public, must-revalidate, proxy-revalidate Connection:Upgrade Content-Encoding:gzip Content-Type:text/html; charset=UTF-8 Date:Fri, 24 Feb 2017 14:45:58 GMT Etag:d12675a57a0072ddbde37b0c8376c442 Expires:Fri, 24 Feb 2017 15:45:58 GMT Keep-Alive:timeout=3, max=20 Pragma:public Server:Apache Upgrade:h2 Vary:Accept-Encoding,User-Agent Via:1.1 win-ip-proxy-02.txhhsc.txnet.state.tx.us:80 (Cisco-WSA/9.0.1-161) X-Powered-By:W3 Total Cache/0.9.4.1 Request Headers view source Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8 Accept-Encoding:gzip, deflate, sdch Accept-Language:en-US,en;q=0.8 Cache-Control:max-age=0 Connection:keep-alive Cookie:utma=157945523.160698973.1487876363.1487876363.1487876363.1; utmz=157945523.1487876363.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none) Host:www.xsanisty.com Upgrade-Insecure-Requests:1 User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

MB34 commented 7 years ago

it has data-formula attribute, so direct input to it is prohibited

So you are saying that you cannot have a formula on a field where you input data??

MB34 commented 7 years ago

Is there a better way to do these formulas on this form? The Excel spreadsheet they were copied from does not have this issue.

ikhsan017 commented 7 years ago

Yes, since it has formula, then it is intended as output, to output the calculation result, not as input

calx does process the formula like spreadsheet, but it isn't a spreadsheet library, just help to process spreadsheet formula in a web form.

my advice is to remove any formula in the input field, and only use it on output field, if you need some kind of validation, you can combine calx with some validation plugin.

here is sample where calx and validationEngine are used together:

http://aminoglycoside-calculator.com/

MB34 commented 7 years ago

I see it now, that formula wasn't supposed to be there.

I, however, cannot get the percentage field formulas to work and the one for the FY 2017 Projected Locally Collected Funds Requirement keeps coming up #ERROR

I have used ValidationEngine before and like it...

MB34 commented 7 years ago

This is how the calculations are supposed to look.

budgetform

ikhsan017 commented 7 years ago

it seems that SUMIF doesn't support wildcard criteria yet as you can see in this line https://github.com/xsanisty/jquery-calx/blob/master/jquery-calx-2.2.7.js#L3513-L3527

you can override default function tho, see registerFunction here http://www.xsanisty.com/project/calx2/calx-api/

MB34 commented 7 years ago

Will SUMIF not work on the values vs. the text in the <select>?

MB34 commented 7 years ago

I have rewritten using a custom function and registered it but get #NAME? in the field.

MB34 commented 7 years ago

Can you help on this last thing?

MB34 commented 7 years ago

I was finally able to get it working:

$('#sheet').calx('registerFunction', 'CYPLCFR', function(args1) { // This gets the values in the select(s) var select_Vals = $('#sheet').calx('getSheet').getCellRangeValue('C15', 'C16'); // initialize to 0; var CYPLCFR = 0; // loop through the selects and if match value, add up the Ppojected Requirement for (var i in select_Vals) { switch (select_Vals[i]) { case 30: case 31: case 32: case 33: case 34: case 35: case 42: case 46: case 47: case 48: case 49: case 50: case 51: case 53: // This sets the corresponding Amount cell "name" var amt_cell = i.replace("C", "E"); // Now get the Amount var value = (!$.isNumeric(parseFloat(args1[amt_cell])) ? 0 : parseFloat(args1[amt_cell])); // And sum it up. CYPLCFR += value; break; }
}; // Then return the sum to the cell return CYPLCFR; });

But how do I keep #NAME from showing when the page initially loads?

ikhsan017 commented 7 years ago

You can try to trigger calculation after registering your function

$('#sheet').calx('registerFunction'...);
$('#sheet').calx('calculate');
MB34 commented 7 years ago

OK, that fixed the #NAME? issue but I am having problems getting the last field to calculate. Everything I try won't make it work in cell E54.

MB34 commented 7 years ago

Also how would I conditionally style any cell whose values were negative?