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

Allow user to enter custom value in calculated field.

New Here ,
Jan 18, 2023 Jan 18, 2023

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! 

 

TOPICS
How to

Views

183

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 ,
Jan 18, 2023 Jan 18, 2023

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;

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 ,
Jan 19, 2023 Jan 19, 2023

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? 

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 ,
Jan 19, 2023 Jan 19, 2023

Copy link to clipboard

Copied

LATEST

It should have worked... Can you share the file?

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