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

Acrobat field script not calculating properly

New Here ,
Mar 01, 2016 Mar 01, 2016

I have a form with a number of fields set to use a custom calculation script. That script is below:

var ro = true;

var plan = Number(this.getField("Option1").value);

if (plan==100)

  event.value = "Included";

else if (plan==125)

  event.value = "Included";

else if (plan==150)

  event.value = "Included";

else if (plan==200)

  event.value = "Included";

else {

  event.value = "";

  ro = false;

}

event.target.readonly = ro;


So based on this the field in question is supposed to take a look at the field named "Option1" and if one of four (4) predetermined values are present ($100, $125, $150 or $200) the field should display "$0" and the field is set as read only.

If none of those four (4) predetermined values are present then the field should unlock to allow for manual data entry.

Everything works fine except that when I tab out of the field it deletes any data I've manually entered.

I am perplexed. Can anyone give any guidance here?

Thanks!

TOPICS
Acrobat SDK and JavaScript
319
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
LEGEND ,
Mar 01, 2016 Mar 01, 2016

It would be much better to not use a calculation script and instead use a custom validation script for the dropdown that sets the value of the text field and controls its read-only property. Something like the following, which assumes there is a dropdown entry that's a single space to indicate no item is selected:

// Custom Validate script for dropdown

(function () {

    // Get a reference to the text field

    var f = getField("Text1");  // Replace with the actual name of the text field

    // Control the value and readonly property of text field

    if (event.value === " ") {

        f.value = "";

        f.readonly = false;

    } else {

        f.value = "Included";

        f.readonly = true;

    }


})();

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
New Here ,
Mar 01, 2016 Mar 01, 2016

Hi George.

Thanks for your response.

Just one thing. I don't have a drop-down.

The way the form works is there are four columns. Each column has approximately 70 fields. The top field of each column is where the "variable" is entered. If either 100, 125, 150 or 200 is entered the desired action is for each of the subordinate 69 fields display a desired value and switch to read-only.

If any value other than the four values I just listed are entered then all 69 subordinate fields switch to allowing manual entry and are no longer read-only.

All of this works fine.

The issue is that if I manually enter data the data is lost upon tabbing out of the field.

Thanks.

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
LEGEND ,
Mar 01, 2016 Mar 01, 2016

OK, for some reason I assumed you were using a dropdown. I would still use the same approach, using a custom validate script in the four Option fields. It should greatly improve the performance and simplify what you want to do. If you'd like help with the script, post again and include the names of the fields for rows 2-70.

The reason your manual entry is getting removed is because your existing calculate script sets the value to an empty string in the final "else" clause of your if statement.

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
New Here ,
Mar 03, 2016 Mar 03, 2016
LATEST

Thanks George.

I've attached in image below of the field names. I've also included a bullet list below that.

Thanks.

Fields.jpg

  1. Option1
    1. frequency01
    2. frequency02
    3. frequency03
    4. frequency04
    5. $ amount01
    6. $ amount02
    7. $ amount03
    8. $ amount04
    9. lenses01
    10. lenses02
    11. lenses03
    12. lenses04
    13. lenses05
    14. lenses06
    15. lenses07
    16. materials01
    17. materials02
    18. materials03
    19. materials04
    20. coatings01
    21. coatings02
    22. coatings03
    23. coatings04
    24. coatings05
    25. coatings06
    26. coatings07
    27. coatings08
    28. contactLenses01
    29. contactLenses02
    30. contactLenses03
    31. contactLenses04
  2. Option2
    1. frequency05
    2. frequency06
    3. frequency07
    4. frequency08
    5. $ amount05
    6. $ amount06
    7. $ amount07
    8. $ amount08
    9. lenses08
    10. lenses09
    11. lenses10
    12. lenses11
    13. lenses12
    14. lenses13
    15. lenses14
    16. materials05
    17. materials06
    18. materials07
    19. materials08
    20. coatings09
    21. coatings10
    22. coatings11
    23. coatings12
    24. coatings13
    25. coatings14
    26. coatings15
    27. coatings16
    28. contactLenses05
    29. contactLenses06
    30. contactLenses07
    31. contactLenses08
  3. Option3
    1. frequency09
    2. frequency10
    3. frequency11
    4. frequency12
    5. $ amount09
    6. $ amount10
    7. $ amount11
    8. $ amount12
    9. lenses15
    10. lenses16
    11. lenses17
    12. lenses18
    13. lenses19
    14. lenses20
    15. lenses21
    16. materials9
    17. materials10
    18. materials11
    19. materials12
    20. coatings17
    21. coatings18
    22. coatings19
    23. coatings20
    24. coatings21
    25. coatings22
    26. coatings23
    27. coatings24
    28. contactLenses09
    29. contactLenses10
    30. contactLenses11
    31. contactLenses12
  4. Option4
    1. frequency13
    2. frequency14
    3. frequency15
    4. frequency16
    5. $ amount13
    6. $ amount14
    7. $ amount15
    8. $ amount16
    9. lenses22
    10. lenses23
    11. lenses24
    12. lenses25
    13. lenses26
    14. lenses27
    15. lenses28
    16. materials13
    17. materials14
    18. materials15
    19. materials16
    20. coatings25
    21. coatings26
    22. coatings27
    23. coatings28
    24. coatings29
    25. coatings30
    26. coatings31
    27. coatings32
    28. contactLenses13
    29. contactLenses14
    30. contactLenses15
    31. contactLenses16
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