Expand my Community achievements bar.

Subtract a value from another field

Avatar

Level 2

Good day to all
I'm still new in creating forms with codes. I'm working on a school project and this one is a bit complicated. I have a form with 100+ fields (all of them are mandatory IF the previous is filled in and some have validation patterns) and a bunch of signature fields. Now, my problem is I want to prevent anyone from printing the form if incomplete (plus the fields with default values). So an idea came, what if I put a invisible text field with initial value of 150 and when the user put a data (!= null) on a field(s), the value of the invisible text field will become 149 and so on.

The real problem is I test the below screenshot (I don't know how to attached pdf files) and whenever I change the value on the first text field, the value of the invisible text field is continuously dropping down.


How to prevent that or is there any workaround?

 

My simple code for the exit event of the first text field:

 

if (this.rawValue == "Value" )
{
form1.page1.Count.count.rawValue - 0;
}
else if (this.rawValue != null)
{
form1.page1.Count.count.rawValue -= 1;
}
else
{

}

The field with initial value of 7 is the "count" in a subform "Count"

Capture.PNG

and my prePrint code is:

 

if (xfa.resolveNode("#subform.count").rawValue > 1)

{

xfa.event.cancelAction = true;
xfa.host.messageBox("Please complete the form");

}

else
{
xfa.event.cancelAction = false;
}

 

2 Replies

Avatar

Level 10

You don't need any scripting or counters at all to prevent the printing. 

Simply add a <validate>-element with the value "prePrint" under the element <config><present> in the XML source view.

radzmar_0-1582378777968.png

 

Avatar

Level 2

Yes, I tried that and it doesn't work on my form. Does the fields needs to be set to "User Entered - Required"? or it will also work on fields that have (mandatory = "error")? Also, the fields will be mandatory if the previous is filled in, and have default value.