Skip to main content
Known Participant
April 1, 2022
Answered

Is there a way to allow end user to overwrite a auto populated text field

  • April 1, 2022
  • 3 replies
  • 2457 views

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!

This topic has been closed for replies.
Correct answer bebarth

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.

@+

3 replies

bebarth
Community Expert
bebarthCommunity ExpertCorrect answer
Community Expert
April 2, 2022

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.

@+

Inspiring
April 4, 2022

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.

try67
Community Expert
Community Expert
April 1, 2022

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?

slaronAuthor
Known Participant
April 1, 2022

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. 

try67
Community Expert
Community Expert
April 2, 2022

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.

JR Boulay
Community Expert
Community Expert
April 1, 2022

Answer is no.

Acrobate du PDF, InDesigner et Photoshopographe