Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
14

Button that allows user to enter numbers that create custom payment schedule

Community Beginner ,
Jan 13, 2024 Jan 13, 2024

Hello,

 

This one may be a bit tricky, so feel free to ask me any questions for clarity.

 

My boss wants to have a button on our contract that allows our consultants to enter a custom pricing schedule. See attached pdf.

 

I've created 3 grey buttons at the top of the form so the user can click on the applicable job type. The general idea is:

 

When the user clicks the "Residential" button, the fields "Phase1_Num",  "Phase2_Num",  "Phase3_Num",  "Phase4_Num", and "Phase5_Num" will show their default values. The pricing above this field should accuractely display the corresponding percentages. For example, the default value for "Phase1_Num" is 10. Therefore, the price shown above this field should be 10% of the "Price" field. The same should apply for all 5 phases so each phase accurately adds up to the total "Price".

 

Here's the tricky part. When the user clicks the "Custom" button, the user should be able to manually enter custom numbers to change the percentages of each phase to their liking. For example, when the user clicks the "Custom" button, they can enter 20 in the "Phase1_Num" field instead of the default value of 10. The price shown above this field should now be 20% of the "Price". The same should apply for all 5 phases.

 

I'm sure there will have to be some rules for this to work. Like the numbers entered for each field have to total up to 100 (Nothing more or less), etc.

 

I'm not even sure if this is possible with Acrobat, but thought I'd give it a try. Thanks in advance for the help!

TOPICS
Create PDFs , How to , JavaScript , Modern Acrobat , PDF , PDF forms
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Jan 13, 2024 Jan 13, 2024

First, the "Custom", "Residential", and "Comercial" buttons need to be radio buttons, so that the mode is a selection that can be acquired at any time, and is saved with the document.  For this discussion the radio button field will be named "Mode" and the exports will be the button titles, i.e. , "Custom", "Residential", and "Comercial" 

 

This makes setting up the custom selection simple. 

Use the MouseUp action on the Custom radio button to set the readOnly and visibility settings of fields the user will need to either change or be blocked from.  

Next, for any field that is calculated and needs to be overwritten by a user entered value, enter this code into the calculation script

 

event.rc = this.getField("Mode").value != "Custom;

 

This code will block the calculation script from affecting the field value, so the user can enter a custom value.

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2024 Jan 13, 2024

First, the "Custom", "Residential", and "Comercial" buttons need to be radio buttons, so that the mode is a selection that can be acquired at any time, and is saved with the document.  For this discussion the radio button field will be named "Mode" and the exports will be the button titles, i.e. , "Custom", "Residential", and "Comercial" 

 

This makes setting up the custom selection simple. 

Use the MouseUp action on the Custom radio button to set the readOnly and visibility settings of fields the user will need to either change or be blocked from.  

Next, for any field that is calculated and needs to be overwritten by a user entered value, enter this code into the calculation script

 

event.rc = this.getField("Mode").value != "Custom;

 

This code will block the calculation script from affecting the field value, so the user can enter a custom value.

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 14, 2024 Jan 14, 2024

Thank you. I guess my last few things to figure out is the validation for the numbers. Not sure how to configure this.

 

For example if the user enters 20 for the first value, the second value must be between 1-80. If they enter 20 for the second value, the third value must be between 1-60. And so on. To put it simply, the number selection decreases as you enter each custom number.

 

Lastly, will this only work if the numbers are entered in order? If the user wants to enter the last number first, will this be possible without any issues? Again, thanks for the help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2024 Jan 14, 2024

For the validation you'll need to work out a methodology, and it must be detailed and specific for all scenarios.  Once you have that it can be coded.  The key to codeing this type of thing is working out the details. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 14, 2024 Jan 14, 2024

I've managed to set up my desired workflow. There is just one last piece to the puzzle.

 

I created a hidden field ("Custom_Calculation") that checks if the custom fields are greater than or less than 100. But I only want the script to run when the "Custom" mode is chosen. Is there a way to block the calculation script while the "Residential" mode is active?

 

I've attached the update version so you can see what I mean.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2024 Jan 15, 2024
LATEST

Since testing is being done in the custom Validation script of the "Custom_Calculation" field, all you need to do is add a test for the mode to the "if".

 

if((this.getField("Mode").value != "Residential") && ...other condition...)

{

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines