Allow user to enter custom value in calculated field.
Copy link to clipboard
Copied
I have a mileage tracking doc that needs help and I have little to no knowledge of Java scripts.
There are three columns (Origin, Destination, and Mileage). Because most people are traveling between specific locations, the Origin and Destination columns are drop-down menus with simple, whole number export values. "Allow user to enter custom text" is selected for both Origin and Destination for times when someone is traveling to a location not included in the drop-downs. However, there's an issue with the calculated Mileage column when custom text is entered -- "The value entered does not match the format of the field [Mileage]."
The Mileage column finds the distance between the two points using simple absolute value and subtraction (below).
event.value = Math.abs(Number(this.getField("ORIGIN1").valueAsString) - Number(this.getField("Destination1").valueAsString));
Is there a way to override this calculation when custom text is added to Origin and Destination, so that there's no error and the user can simply type in a value for mileage?
Thanks in advance!
Copy link to clipboard
Copied
Try using this code:
if (this.getField("ORIGIN1").currentValueIndices!=1 && this.getField("Destination1").currentValueIndices!=1) {
event.target.readonly = true;
event.value = Math.abs(Number(this.getField("ORIGIN1").valueAsString) - Number(this.getField("Destination1").valueAsString));
} else event.target.readonly = false;
Copy link to clipboard
Copied
Thanks so much!!! That works for editing the set outputs from the drop-downs, but the error message still appears when you enter custom text into origin and destination. Users need the option to enter a custom Origin, Destination, and Mileage. I do have it set to allow user to enter custom text. Any help with that?
Copy link to clipboard
Copied
It should have worked... Can you share the file?

