Copy link to clipboard
Copied
I have a text field,"Text 2", that includes the following JavaScript in the calculation field that auto populates this text field from two previous text fields:
event.value = this.getField("Text A").valueAsString + " " + this.getField("Text B").valueAsString;
In most cases what would then populate the "Text 2" field would be correct, but sometimes the end user might want to alter the resulting text in "Text 2". Is there anything that could be added to the above script that would allow the end user overwrite what has auto populated in the "Text 2"?
Thank you in advance for time and help!
Hi,
For me it's possible. Write:
if (event.source && (event.source.name=="Text A" || event.source.name=="Text B")) event.value=this.getField("Text A").valueAsString+" "+this.getField("Text B").valueAsString;
But as soon as you modify the "Text A" or "Text B" field the "Text 2" field is "Text A" value + " " + "Text B" value.
@+
Copy link to clipboard
Copied
Answer is no.
Copy link to clipboard
Copied
It is possible, actually, but you need to clearly define how it should work first.
Say the user changed the value manually, but then went back and changed either "Text A" or "Text B".
Should it then revert back to the calculated value, or should it keep the value they entered before?
Copy link to clipboard
Copied
Ideally, once the user overwrites the calculated value, the field would keep the new value entered regardless of whether "Text A" or "Text B" was changed.
Copy link to clipboard
Copied
That's more tricky to do. You will need to keep a record of when the field was edited, in order to stop applying the calculated value to it.
Copy link to clipboard
Copied
Hi,
For me it's possible. Write:
if (event.source && (event.source.name=="Text A" || event.source.name=="Text B")) event.value=this.getField("Text A").valueAsString+" "+this.getField("Text B").valueAsString;
But as soon as you modify the "Text A" or "Text B" field the "Text 2" field is "Text A" value + " " + "Text B" value.
@+
Copy link to clipboard
Copied
This doesn't make any sense, it's opposite of what OP asked for,
Ideally, once the user overwrites the calculated value, the field would keep the new value entered regardless of whether "Text A" or "Text B" was changed.
Copy link to clipboard
Copied
Very helpful--that works just as you described. Thank you!