Copy link to clipboard
Copied
I have a radio button named group6. There are 3 options to choose from directorder, POR, buildandreplace.
Depending on which option you choose determines which columns of the table need to be filled out. If you select directorder or POR, then if you fill out an item code and you must enter the quantity in that row of the table. If you select billandreplace and all the columns in the order form are required. Below is an image of the order form.
The 1st row the item code name is itemcode1.0. So the action for that field is set to mouse up and run JavaScript. Here is the script that I wrote:
if (event.value.length>0 && getField("group6").value == "directorder") {
this.getField("qty1.0").required = true;
}
I would repeat this code for each item code row. But it's not working. What am I doing wrong? I have it set so that the form validates prior to being submitted. It alerts the user of any required fields that are not filled in. If I enter an item code none of the required fields are mentioned in the alert.
Copy link to clipboard
Copied
Put this code as "calculation script" in one of the fields:
for( var i=0; i<=11; i++){
if(this.getField("itemcode1."+i).valueAsString != "" && (this.getField("group6").valueAsString == "directorder" || this.getField("group6").valueAsString == "POR")){
this.getField("qty1."+i).required = true;
this.getField("serialnumber1."+i).required = false;
this.getField("servicefee1 replace1."+i).required = false;}
else if(this.getField("itemcode1."+i).valueAsString != "" && this.getField("group6").valueAsString == "billandreplace"){
this.getField("qty1."+i).required = true;
this.getField("serialnumber1."+i).required = true;
this.getField("servicefee1 replace1."+i).required = true;}
else {
this.getField("qty1."+i).required = false;
this.getField("serialnumber1."+i).required = false;
this.getField("servicefee1 replace1."+i).required = false;}}
Copy link to clipboard
Copied
Please share your file or show screenshot of field names.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Ok, just quick question. If item code is filled and rb directorder or POR is selected only qty column is required, and if billandreplace is selected all fields are required?
Copy link to clipboard
Copied
Yes, if direct order or POR is selected, then if a item code is entered then the only other required field in that row is qty. If billandreplace this is selected, then if an item code is entered then all of the fields are required in that row.
People can order as many items as they like, so the required fields are also contingent on if there is something entered in the item code.
Does that make sense? So if you're only ordering 2 items, it only affects the 1st 2 rows.
Copy link to clipboard
Copied
Put this code as "calculation script" in one of the fields:
for( var i=0; i<=11; i++){
if(this.getField("itemcode1."+i).valueAsString != "" && (this.getField("group6").valueAsString == "directorder" || this.getField("group6").valueAsString == "POR")){
this.getField("qty1."+i).required = true;
this.getField("serialnumber1."+i).required = false;
this.getField("servicefee1 replace1."+i).required = false;}
else if(this.getField("itemcode1."+i).valueAsString != "" && this.getField("group6").valueAsString == "billandreplace"){
this.getField("qty1."+i).required = true;
this.getField("serialnumber1."+i).required = true;
this.getField("servicefee1 replace1."+i).required = true;}
else {
this.getField("qty1."+i).required = false;
this.getField("serialnumber1."+i).required = false;
this.getField("servicefee1 replace1."+i).required = false;}}
Copy link to clipboard
Copied
When I entered that script as a custom calculation script, it automatically defaults back to the "value is not calculated" option. It won't except that code. Any thoughts on why?
Copy link to clipboard
Copied
Can you share your file?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I didn't have any problem inputing script into field.
Try now:
https://drive.google.com/uc?export=download&id=19wsY8qyNSi6Z_ZNez8je5MEHF2qoB7bA
Copy link to clipboard
Copied
Sorry to be a pain. Where exactly did you enter the code? That seems to be my problem. I'm not doing it in the right space.
Copy link to clipboard
Copied
Nevermind I found it
Copy link to clipboard
Copied
I don't know why but that is where I would put it, and would click okay and it would not insert the code. Anyway, thank you so much for your help.