fields with null value
-
Hi,
I’m trying to calculate MIN of 9 fields. Each field relates to how old a child is. up to 9 fields are displayed based on “how many children do you have”
my MIN function in the calculation field looks at the entries of all 9 fields. If the user only has 2 children and enters ages for those children, the plugin seems to think the other 7 values are 0 rather than “null” therefore returning a 0 rather than the age of the youngest child.
A’m i missing something?
Thanks
Stuart
-
Hi @gingerstu,
I don’t think there’s anything I can do to fix your issue, unfortunately. The
nullvalues are already converted to zeroes in the formula by the time my plugin tries to parse the MIN/MAX functions :-/Could you do something in the form itself so that this formula isn’t enabled until valid values have been provided for the children’s ages? Basically assure that something greater than zero has been entered for the ages?
Best,
George MandisHi George . Thanks for the follow up. I assumed something along these lines
I managed to fix it with some java script. I’ll post that later when I’m in front of my laptop. It may help out someone else in the futureThanks
StuartThe code create a variable for each field, obtaining the value from the field ID
it then tests to see if there is a null entry, if there is, it does nothing, is there isn’t a null entry, it than places that value into an array.
It checks each field building the array as it goes.
it gets to the end, performs a check to obtain the minimum number, writes that to a variable and then updates the field that is meant to contain the minimum number from the array.
Hope this helps someone out in the future.
var c1a; var c2a; var c3a; var c4a; var c5a; var c6a; var c7a; var c8a; var c9a; var minca; const check_age = [] c1a = document.getElementById('input_19_29').value; c2a = document.getElementById('input_19_30').value; c3a = document.getElementById('input_19_31').value; c4a = document.getElementById('input_19_32').value; c5a = document.getElementById('input_19_33').value; c6a = document.getElementById('input_19_34').value; c7a = document.getElementById('input_19_35').value; c8a = document.getElementById('input_19_37').value; c9a = document.getElementById('input_19_38').value; if(c1a == "" ){ } else{ const count = check_age.push(c1a) } if(c2a == ""){ } else{ const count = check_age.push(c2a) } if(c3a == ""){ } else{ const count = check_age.push(c3a) } if(c4a == ""){ } else{ const count = check_age.push(c4a) } if(c5a == ""){ } else{ const count = check_age.push(c5a) } if(c6a == ""){ } else{ const count = check_age.push(c6a) } if(c7a == ""){ } else{ const count = check_age.push(c7a) } if(c8a == ""){ } else{ const count = check_age.push(c8a) } if(c9a == ""){ } else{ const count = check_age.push(c9a) } minca = Math.min(...check_age); document.getElementById('input_19_99').value = minca;-
This reply was modified 6 years, 1 month ago by
gingerstu.
Hi @gingerstu,
I think this could be a little more manageable if you push all the values into an array (including
nullvalues) and use thefiltermethod to remove all thenullvalues before getting the minimum value.I can’t test it because I can’t see the exact code you’re working with, but I think you could reduce your code to something like this:
// if all of the inputs that begins with .input_19_ are ages you can get them // in a single selector like this. Otherwise, probably your approach. Alternately, // you could give them fields a custom, unique class name when building the form. const inputs = Array.from(document.querySelectorAll('input[class^="input_19_"]')); // This will create an array that only contains the input elements values and // filters out any false-y values (including null) const filteredValues = inputs.map((el) => el.value).filter(_=>_); // Now we can safely push all these values to your array knowing nulls // have been stripped. check_age.push(...filteredValues); // The rest of the code should work as before const minca = Math.min(...check_age); document.getElementById('input_19_99').value = minca;Maybe it can’t be exactly that way, but does this help clean up anything?
Best,
GeorgeThat’s awesome George – much tidier solutiion. Mine was cobbled together with literally zero scripting experience. I’ll see if I can implement yours as it’s more adaptable should i want to add more fields at a later date.
Thanks again,
StuartHappy to help @gingerstu! 🙂
Going to close this for now.
Hi, I have the same problem.
I’m entering this formula
MIN({Value1:68},{Value2:70},{Value3:71},{Value4:90},{Value5:91},{Value6:92},{Value7:93} )My problem is not all the values have a value 🙂 and so I get a 0.
I would like to discharge those zeros. I’m not good with Java. Any chance I can add a line to your plugin to not accept those zeros as value?
If so, where should I enter those lines?
I tried at the minmax.php file but nothing changed.
Please I need some help. Thanks.
Hi @mencho22,
I don’t think this forum is going to be the best place to help you. It’s a little hard to troubleshoot just based on the formula. it’s also not technically a problem specific to this plugin.
Have you tried searing the WordPress Stack Exchange?
https://wordpress.stackexchange.com/questions/tagged/plugin-gravity-forms
I think it might be more effective to try there.
Sorry and best of luck!
-
This reply was modified 6 years, 1 month ago by
The topic ‘fields with null value’ is closed to new replies.