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

Selecting Specific Text within a Text Field

Participant ,
May 03, 2021 May 03, 2021

I am looking for a way (potentially using JavaScript) to have a portion of text within a field be selected upon entering a field. Below is an example:

 

Screenshot 2021-05-03 162318.jpg

My intention is for the document to increment the highest photo number currently in use by 1 (which is usually what the user will want) and place that after the user's initials. The part I need help with is to select the text of the number in case this "prediction" is wrong. This will enable the user to simply begin typing the number they want in the event that they threw away a photo or otherwise skip a number.

I am using the latest version of Acrobat Pro DC. Thank you for reading, and I appreciate any help anyone has to offer!

TOPICS
Create PDFs , PDF forms
1.4K
Translate
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 ,
May 03, 2021 May 03, 2021

I don't believe that's possible using a script.

Translate
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 ,
May 03, 2021 May 03, 2021

What I would do instead is populate the field when the user clicks into it with the next number using the On Focus event (maybe checking it's not empty first, as to not overwrite any custom values the user entered before). This will allow the user to change the value if they wanted to, or just tab to the next field if the automatic value is correct.

Translate
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
Participant ,
May 03, 2021 May 03, 2021

Okay, I see this potentially still doing exactly what I want. For now I have a simple script putting in the user's intials with the On Focus:

if(event.target.value == ""){
    event.target.value = this.getField("Camera").value;
}

With this, the text which is input is not selected. Is there a way to have everything selected once the desired info is "typed in"?

Translate
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 ,
May 03, 2021 May 03, 2021

The only way to select the text of a field is to set focus to it, which you can do like this:

this.getField("FieldName").setFocus();

This would select the full contents of that field.

Translate
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 ,
May 03, 2021 May 03, 2021

I don't think this would work on the On Focus event, though, as the field already has the focus at that moment...

Translate
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
Participant ,
May 03, 2021 May 03, 2021

Okay, I need a way to have the text selected once the user enters the field. Let's start there. Is that possible? Can I call a doc level function that then calls setFocus() back to the field or something?

Translate
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 ,
May 03, 2021 May 03, 2021
LATEST

I don't think so. It will only work if you set the focus to another field and then back to it, but that would create an endless loop... I think you're over-complicating this. Use the initial method I described, or abandon this idea.

Translate
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
Participant ,
May 03, 2021 May 03, 2021

Then I can have the initials added to the beginning with an On Blur trigger (hopefully).

Translate
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