Title: fields with null value
Last modified: March 20, 2020

---

# fields with null value

 *  Resolved [gingerstu](https://wordpress.org/support/users/gingerstu/)
 * (@gingerstu)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/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

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [George Mandis](https://wordpress.org/support/users/georgemandis/)
 * (@georgemandis)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/fields-with-null-value/#post-12569465)
 * Hi [@gingerstu](https://wordpress.org/support/users/gingerstu/),
 * I don’t think there’s anything I can do to fix your issue, unfortunately. The`
   null` values 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 Mandis
 *  Thread Starter [gingerstu](https://wordpress.org/support/users/gingerstu/)
 * (@gingerstu)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/fields-with-null-value/#post-12570770)
 * Hi 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 future
 * Thanks
    Stuart
 *  Thread Starter [gingerstu](https://wordpress.org/support/users/gingerstu/)
 * (@gingerstu)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/fields-with-null-value/#post-12571602)
 * The 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, 2 months ago by [gingerstu](https://wordpress.org/support/users/gingerstu/).
 *  Plugin Author [George Mandis](https://wordpress.org/support/users/georgemandis/)
 * (@georgemandis)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/fields-with-null-value/#post-12576581)
 * Hi [@gingerstu](https://wordpress.org/support/users/gingerstu/),
 * I think this could be a little more manageable if you push all the values into
   an array (including `null` values) and use the `filter` method to remove all 
   the `null` values 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,
    George
 *  Thread Starter [gingerstu](https://wordpress.org/support/users/gingerstu/)
 * (@gingerstu)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/fields-with-null-value/#post-12577187)
 * That’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,
    Stuart
 *  Plugin Author [George Mandis](https://wordpress.org/support/users/georgemandis/)
 * (@georgemandis)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/fields-with-null-value/#post-12587897)
 * Happy to help [@gingerstu](https://wordpress.org/support/users/gingerstu/)! 🙂
 * Going to close this for now.
 *  [mencho22](https://wordpress.org/support/users/mencho22/)
 * (@mencho22)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/fields-with-null-value/#post-12643392)
 * 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.
 *  Plugin Author [George Mandis](https://wordpress.org/support/users/georgemandis/)
 * (@georgemandis)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/fields-with-null-value/#post-12643434)
 * Hi [@mencho22](https://wordpress.org/support/users/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](https://wordpress.stackexchange.com/questions/tagged/plugin-gravity-forms)
 * I think it might be more effective to try there.
 * Sorry and best of luck!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘fields with null value’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/gf-minmax-calculation_b48fd7.svg)
 * [Gravity Forms MIN/MAX Calculation](https://wordpress.org/plugins/gf-minmax-calculation/)
 * [Support Threads](https://wordpress.org/support/plugin/gf-minmax-calculation/)
 * [Active Topics](https://wordpress.org/support/plugin/gf-minmax-calculation/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gf-minmax-calculation/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gf-minmax-calculation/reviews/)

 * 8 replies
 * 3 participants
 * Last reply from: [George Mandis](https://wordpress.org/support/users/georgemandis/)
 * Last activity: [6 years, 1 month ago](https://wordpress.org/support/topic/fields-with-null-value/#post-12643434)
 * Status: resolved