Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

Subtract a value from another field

esdigrap
Level 2
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
radzmar
Level 10
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

 

esdigrap
Level 2
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.