PDF Form has a field for Weekly Hours (totalField) and 7 fields for days of the week(Mon 1, Tue 1, Wed 1, etc.)
1. user can enter their total into totalField; or
2. user can enter their hours for each day of the week. totalField becomes readonly and calculates.
My code is not perfect. It works, but it has an error (InvalidSetError: Set not possible, invalid or unknown. Field.value:46). The error arises if 1. user enters their total into totalField. The form functions just as it should. But I would like to learn how to do this without relying on the error. Error line labeled below:
var Sun = Number(this.getField("Sun 1").valueAsString);
var Mon = Number(this.getField("Mon 1").valueAsString);
var Tue = Number(this.getField("Tue 1").valueAsString);
var Wed = Number(this.getField("Wed 1").valueAsString);
var Thu = Number(this.getField("Thu 1").valueAsString);
var Fri = Number(this.getField("Fri 1").valueAsString);
var Sat = Number(this.getField("Sat 1").valueAsString);
var totalField = this.getField("Total Field");
var schedTotal = 0;
if (!isNaN(Sun)) schedTotal+=Sun;
if (!isNaN(Mon)) schedTotal+=Mon;
if (!isNaN(Tue)) schedTotal+=Tue;
if (!isNaN(Wed)) schedTotal+=Wed;
if (!isNaN(Thu)) schedTotal+=Thu;
if (!isNaN(Fri)) schedTotal+=Fri;
if (!isNaN(Sat)) schedTotal+=Sat;
// if schedule is empty, Total Field text and Day field boxes are light gray and all editable//
if(schedTotal == 0 && totalField == "Total") {
totalField.value = "Total";
totalField.textColor = color.ltGray;
totalField.readonly = false;
this.getField("Sun 1").strokeColor = color.ltGray;
}
//if validnumber entered into day fields, Total Field calculates and text is black//
else if((schedTotal > 0) && (schedTotal <= 37.5)) {
totalField.value = schedTotal;
totalField.textColor = color.ltGray;
totalField.readonly = true;
this.getField("Sun 1").strokeColor = color.ltGray;
} else if((schedTotal == 0) && (totalField !== "Total")) {
totalField.value = "Total"; // Error on this line//
totalField.textColor = color.ltGray;
totalField.readonly = false;
this.getField("Sun 1").strokeColor = color.ltGray;
} else if(schedTotal==0) {
totalField.textColor = color.ltGray;
totalField.value = "Total";
totalField.readyonly = false;
this.getField("Sun 1").strokeColor = color.ltGray;
}