Expand my Community achievements bar.

How to uncheck checkboxes when a is empty - or how to not calculate non values

Avatar

Level 1

I have 2 numeric fields. When one field is greater than or equal to the second field a checkbox is checked. When the field is empty, what code do you use to ensure the checkbox is unchecked???

So far I'm using the following if statement using FormCalc and the calculation drop-down:

if (NumericField14 >= NumericField15) then

  this.rawValue = 1;

else

  this.rawValue = 0;

  endif

So by default it looks like this:

uncheck by default.png

How do you get the statement to not count non-values or nulls?? I've tried adding the following null statement in but I get an error message:

(theField.isNull | theField == "")

Any help is appreciated!

5 Replies

Avatar

Level 1

I tried this.rawValue to set a checkbox value and it worked.

Regarding this code line:

(theField.isNull | theField == "")

I can spot a few errors, although I'm not a Javascript expert:

1) You probably meant to use the logical or operator, which is ||, not |. You can.literally use the word 'or' also.

2) The first check theField.isNull is written in a very short C-specific fashion, but I'm not sure it works in Javascript. Try using the full form: theField.isNull == null.

3) The second check should be theField.rawValue not theField. You did use the rawValue property yourself when writing this.rawValue, and it looks like you get an error (no defauly property) if you don't specify one.

It appears to me after some testing that theField.isNull == null would be the right choice. The second one only applies if you explicitly assign the empty string to the field.

Avatar

Level 1

Thank you TudorCT for the response and testing. Thank you for explaining the errors and the full form of the null statement, it's appreciated.

I'm a beginner in coding. Could you tell me where I would insert your statement "theField.isNull == null" in my if statement?

Screen shot.png

Thank you so much, I've been working on this statement for 3 hours so would appreciate a response, hank you!

Avatar

Level 1

First of all, I wrote in a hurry, and there is a mistake in my own coding: use "theField.isNull == true" so instead of  "theField.isNull == null".

That's because theField.isNull returns either true or false.

Then, you can create a global variable to count your empty checkboxes.

Use from the menu: Edit -> Form Properties -> Variables.

A name is required for the variable, e.g  counter. And you can also assign an initial value of 0 from the same spot.

Then get back to the script above and something like this:

if ( theField.isNull == true)

     counter = counter + 1.


Looking at your screenshot, I can also see that you've written JavaScript code, but you're telling Livecycle that you use Formcalc (Adobe's own language). There is a dropdown list to the right, currently showing FormCalc. Make sure to switch this back to JavaScript!

What do you want to do with the number of empty checkboxes? To display in a text field, you should use a code like

this.value = counter;

for the calculate event of the respective field.

(Pay attention to the language setting for that field also.)

Avatar

Level 1

Thanks for more details.

I've made the changes with your recommendations in your post above and changed it to JavaScript. When I add the Null statement into the current expression, it stops tallying my numeric fields.

With the number of the empty checkboxes I didn't want it to calculate, for example:

  • If numeric field 1 & 2 are empty or zero then the checkbox A would be unchecked.

Right not it's defaulted to checked and it shouldn't be. If I add in your if statement it does go unchecked but it stops calculating the remaining if statement, for example I still need it to the following:

  • If numeric field 1 is >=  numeric field 2 then checkbox A would be checked.
  • If numeric field 1 is < numeric field 2  then checkbox B would be checked. (this calculation works fine because it doesn't have the equal sign)

The null statement stops calculating the above to bullet points unfortunately.


I'd upload the file but I don't have rights.


Thanks for the help, not sure if I'll get this one though.