Skip to main content
first.officer
Inspiring
February 6, 2022
Answered

Text field with prefix, but allows editing by user if desired....

  • February 6, 2022
  • 1 reply
  • 1037 views

Hi all,

 

Am wondering if it is possible to allow for a prefix in a field that sets "AW" as the prefix, but then if the user decides to delete/overwrite, then they could overwrite with anything they may desire, e.g. say "BD", or "CC" and add any additional text/numbers after this, or any variation thereon...script I have thus far is;

 

if (event.value) event.value = "AW " + event.value;

 

Thanks!

This topic has been closed for replies.
Correct answer try67

I don't quite follow what you mean there, but one possible solution is to only add the prefix if the field was empty before the user entered something into it. You can do it by using the following code as the custom Validation script for that field:

 

if (event.value && event.target.value=="") {
	event.value = "AW " + event.value;
}

1 reply

try67
Community Expert
Community Expert
February 6, 2022

How would the script know not to add the prefix again after the user changed it to something else, though?

first.officer
Inspiring
February 6, 2022

Yes, this is true.....I was just wondering if there was a weird and wonderful way of working around it lol.....I could have two fields, one over the other and a 'check box' that the user selects and the relevant field is then displayed (or triggered on a drop-down etc,), but thought i'd see if there was a more 'elegant' solution ;-).

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 6, 2022

I don't quite follow what you mean there, but one possible solution is to only add the prefix if the field was empty before the user entered something into it. You can do it by using the following code as the custom Validation script for that field:

 

if (event.value && event.target.value=="") {
	event.value = "AW " + event.value;
}