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

Conditionally set the required text fields on my form based on user answers from a radio button?

New Here ,
Nov 17, 2020 Nov 17, 2020

Copy link to clipboard

Copied

Hi , i have 2 radio buttons (T+2 & choice T+3  ). If i select choice 1, the value input in text field (T + ?) column should be 0 ≤ 2 and choice 2 should output 3 ≤ 11 number. How to script this . Attached below is the snapshot of form.

radio button.JPG

Please help and thanks in advance.

TOPICS
Acrobat SDK and JavaScript

Views

535

Translate

Translate

Report

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

correct answers 2 Correct answers

Community Expert , Nov 18, 2020 Nov 18, 2020

Try something like this, put code in each "TRow" field as custom validation script, also if needed change export values for radio buttons ( I assumed they are T2 and T3):

var rb = this.getField("Group1").valueAsString;
if(rb == "T2"){
if(event.value < 0 || event.value > 2){
app.alert("Enter number between 0-2.");
event.value = "";}}
else if(rb == "T3"){
if(event.value < 3 || event.value > 11){
app.alert("Enter number between 3-11.");
event.value = "";}}

Votes

Translate

Translate
Community Expert , Nov 20, 2020 Nov 20, 2020

+++Adding to this discussion,

 

I thought that you asked how to do this straight from the radio buttons. NesaNurani answer is pretty much what you need; is simple, and to the point.

 

If you want this work through the radio buttons though, it is a lot more complicated than I thought.

 

I had to get out of the basic scripting comfortable zone in order to make it work from the radio buttons as a MouseUp event, not as a custom calculation script copied on every field manually. You can, however, cop

...

Votes

Translate

Translate
New Here ,
Nov 17, 2020 Nov 17, 2020

Copy link to clipboard

Copied

Jey5EFE_0-1605669445610.png

Ps : this is the row name .

 

Votes

Translate

Translate

Report

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 ,
Nov 17, 2020 Nov 17, 2020

Copy link to clipboard

Copied

can you be a little more specific about the workflow that you're trying to achieve?

Votes

Translate

Translate

Report

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 ,
Nov 17, 2020 Nov 17, 2020

Copy link to clipboard

Copied

Hi there, sure

 

Based on the screenshot above, selecting radio button 1 (T+2 & BELOW) should limit the user from key-in number value between 0 - 2 in T + ? row (highlighted field). If user select radio button 2 (T+3 & ABOVE) , the input value limit should between 3 - 11 for each row.

 

PS : User can key in up to 6 rows based on their radio button selected.

Votes

Translate

Translate

Report

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 ,
Nov 18, 2020 Nov 18, 2020

Copy link to clipboard

Copied

Try something like this, put code in each "TRow" field as custom validation script, also if needed change export values for radio buttons ( I assumed they are T2 and T3):

var rb = this.getField("Group1").valueAsString;
if(rb == "T2"){
if(event.value < 0 || event.value > 2){
app.alert("Enter number between 0-2.");
event.value = "";}}
else if(rb == "T3"){
if(event.value < 3 || event.value > 11){
app.alert("Enter number between 3-11.");
event.value = "";}}

Votes

Translate

Translate

Report

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 ,
Nov 20, 2020 Nov 20, 2020

Copy link to clipboard

Copied

LATEST

+++Adding to this discussion,

 

I thought that you asked how to do this straight from the radio buttons. NesaNurani answer is pretty much what you need; is simple, and to the point.

 

If you want this work through the radio buttons though, it is a lot more complicated than I thought.

 

I had to get out of the basic scripting comfortable zone in order to make it work from the radio buttons as a MouseUp event, not as a custom calculation script copied on every field manually. You can, however, copy a caalculated script onto every field with one action event triggered when a radio button is checked.

 

This matters if you a have a table with more than 50 "TotalRow" fields on 3 pages across the same PDF,  and more than just a pair of mutually exclusive checkboxes or radio buttons grouped with different names and export values. 

 

So I came up with this: Using a for loop script you can set an custom calulation script through the "setAction()" method and define it with parameters that will affect the behavior on each of the TRow fields when the script is executed.

 

An event action will allow to define a keystroke script, a validation script, and/or a custom calculation script.

 

All of this is possible with the setAction() method. 

 

In my example, I named both of the radio buttons as "T",  and assigned different export values to each one (i.e. Choice1 and Choice2 respectively).

 

In  the T+2 radio button (with export value of "Choice1") I used this script:

 

for (var i = 0; i < 6; i++) 

this.getField("TRow"+i).setAction("Calculate", "if(event.target.value >=3 || event.target.value < '0')  event.value =''; else event.value =  util.printf('%d', event.target.value);");

 

 

In  the T+3 radio button (with export value of "Choice2") I used this script:

 

 

for (var i = 0; i < 6; i++) 

this.getField("TRow"+i).setAction("Calculate", "if(event.target.value >=12 || event.target.value <= 2)  event.value =''; else event.value =  util.printf('%d', event.target.value);");

 

 

 

 

Votes

Translate

Translate

Report

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