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

Replace default text onMouseDown, with new text, so user can type after the new text

Explorer ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

Hi Forum Whizzes,

This is such a trivial little thing, but it is really bothering me that I can't make it work.

I have a form which contains many input fields for Name, Address, Website, Email, Phone Number, etc. One of the pieces of data I would like the user to supply is the name of their Instagram account ie: @AcrobatJavascriptDunce (Which should probably be mine...)

Rather than have external titles for the fields, the style on the form is that the text box contains default text, which tells the user what they need to put in the box. So the default text for the Website field is "Website", obviously, and the default text is displayed in red. I have it set up so that when the user clicks on that field, the default text disappears, and the cursor is in the box ready to type, and when they DO type, the text is now displayed in black. It all works very nicely for my other fields, but for the Instagram field, I would like the action to be subtly different.

When the user clicks on the default text (which happens to be "@instagram" as that tells them the format I would like them to enter the name in), I want the red text to disappear as before, but instead of a blank field, I want the field to just contain the "@", so that when they type, whatever they type comes after the "@". This is simply a little timesaver for using the form, but it will be a nice convenient touch.

At the moment I am using the following script, set as an action onMouseDown:

if (event.target.value == event.target.defaultValue) {

     event.target.value="@";

     event.target.textColor=color.black;

}

It works apart from one tiny-but-crucial detail: when I click in the field, the default text disappears, and a black "@" takes its place, but unfortunately, the cursor is to the left of the "@" sign, so anything that the user types into the box ends up on the wrong side, and the Instagram name has the "@" at the end!

Is there a way to specify that the cursor appears at the end of the text, rather than before it?

Thanks so much for your help. Any advice will be VERY gratefully received.

Best wishes,

NathanG

TOPICS
Acrobat SDK and JavaScript

Views

961

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

correct answers 1 Correct answer

Explorer , Apr 19, 2019 Apr 19, 2019

Hello Thom, it is with great chagrin that I realise I didn't respond to your post on this thread. That must have seemed incredibly ungrateful of me, particularly after you have been so helpful to me in the past.

The solution that works the best for me was actually to use one of the options in your very useful formatting_text_fields pdf, where instead of the currency symbol, I used the code for the "@" symbol, and it works like a charm.

I will now mark this thread as solved, but if you have the tim

...

Votes

Translate

Translate
Community Expert ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

Use the keystroke script instead of the MouseDown.  This will give the script control over the entered data and the cursor position. I would suggest using this script to ensure that the first character is "@", rather than pre-entering it.  This is a bit complex so you'll need to play around with it a bit.

Also, do not make the default value @instagram. Instead, use the custom format script to display this value when the field is blank.

Here's a short tutorial on using these scripts.

https://acrobatusers.com/tutorials/formatting_text_fields

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Explorer ,
Apr 19, 2019 Apr 19, 2019

Copy link to clipboard

Copied

Hello Thom, it is with great chagrin that I realise I didn't respond to your post on this thread. That must have seemed incredibly ungrateful of me, particularly after you have been so helpful to me in the past.

The solution that works the best for me was actually to use one of the options in your very useful formatting_text_fields pdf, where instead of the currency symbol, I used the code for the "@" symbol, and it works like a charm.

I will now mark this thread as solved, but if you have the time, I wonder if you would mind explaining just why it is that you recommend the keystroke section rather than an action on Mousedown? I wasn't able to get it working for me at all using the keystroke, but using the mousedown function, it certainly appears to behave exactly as I wanted it to, but obviously, I know next to nothing about the ins and outs of what goes on underneath the user interface, so there might be reasons that I can't envisage why the way I have done it now might be a bad idea, or cause conflict, or in some way adversely affect something I'm unaware of.

Perhaps it's a style thing, or whatever, but I'm very interested and keen to learn whatever I can, so any perspective would be gratefully received.

Thanks again for your time. I really do appreciate the help that you and others on these forums give and have given me.

All the best, Nathan

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 ,
Apr 22, 2019 Apr 22, 2019

Copy link to clipboard

Copied

The mouse down is completely unrelated to data entry. For a data oriented operation you need to use a data oriented event.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Apr 29, 2019 Apr 29, 2019

Copy link to clipboard

Copied

You actually don't want to pre-fill the "@" text for the Instagram field as you describe. It's not a time saver because when a user enters a field, the text in the field is selected and typing anything replaces what's there. If they aren't paying attention and manually moving the insertion point to the end, they'll still have to type in the "@".

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 Beginner ,
Jul 12, 2023 Jul 12, 2023

Copy link to clipboard

Copied

LATEST

Nathang - could you please provide how you are getting the default text to disappear? I am currently trying to help my aunt with a form for her travel agency and am coming up short. 

I have the firm in Adobe and I need to get the fields to have a default value to show users what to type for example: street address, city, state, zip and when they click in the box for the default text to disappear and the user can start typing their value. I can get to the point that the user can input information but they have to highlight the text to erase and type. 

I also cannot get the typed values to print.

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