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

Explorer ,
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

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

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

505

Likes

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

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

Explorer ,
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

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

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

506

Likes

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
Apr 02, 2019 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Apr 02, 2019 0
Explorer ,
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

Likes

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
Reply
Loading...
Apr 19, 2019 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Apr 22, 2019 0
Adobe Community Professional ,
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 "@".

Likes

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
Reply
Loading...
Apr 29, 2019 0