Expand my Community achievements bar.

Text Field - Get selected text

Avatar

Level 4

Hello everyone,

I was wondering if there was some way to get the selected text from a text field. The way I see this working is that in either javascript or formcalc, on exit, the selected text is either saved to a form level variable, or to the clipboard automatically.

I've read around the forums, and I've tried to wade through the properties/methods of the text field... but I couldn't find anything of the sort.

Is this sort of thing possible?

- Scott

7 Replies

Avatar

Former Community Member

The text entered in to a Text Field object is available in the exit event as this.rawValue.

Steve

Avatar

Level 4

This only provides the full text of the text box... I was hoping to get the selected text...

Now, I know that the selected text is lost when the field loses focus, but I also know that the selected text remains selected until after the exit event fires fully.

To test this, thow an 'xfa.host.messageBox("is it still selected?")' into the exit event of a text box... Run the form, write a line, select a part of it, then exit the text box. You'll get an alert, and the text is still selected. The way I see it, this would be as good a time as any to get the selected text, I just need to know how.

I've tried several javascript methods, but they were all designed for web browsers. The only thing else that is similar that I can find is the selStart/selEnd attributes that get filled  with the selection indexes on the change event. I'm just now looking at how these attributes work.

Does anyone know if it's possible to use these attributes to get the selected indexes on exit?

Thanks again for any help.

- Scott

Avatar

Former Community Member

This is not possible. What is the use case?

Steve

Avatar

Level 4

My users want to be able to select some text, press a button and have formatting applied to the selection. I know that adobe has some primitive formatting for rich text fields... bold, italics, font, color, etc... but they want all of these buttons incorporated on the form itself. Also, there are some custom effects that my users want... as in bullets, lists, tabs, etc.

I'm still playing with the selStart/End... but no luck yet,

- Scott

Avatar

Former Community Member

Yes, xfa.event.selStart and xfa.event.selEnd can be used on the change event but the properties are populated with the indexes upon change only. I don't see how they can be used to capture the start and end index based upon focus and highlighting alone.

Steve

Avatar

Former Community Member

If you are trying to apply richText attributes to the text then doing it programmatically will be very difficult. Once in the field you can hit the Ctrl-E key sequence the Rich Text Field toolbar will appear and allow you to apply the appropriate styles to the selected text.

Hope that helps

Paul

Avatar

Level 4

Hello again,

I knew that it would be difficult when I started this project, but I like to think that nothing is impossible. I already have a working knowledge of how to dynamically format text, thanks to a tutorial that provided an 'envelope' for formatted text. I'm able to have a button called bold, and a textbox where the user enters the start/stop indexes. I have that test form working, I just want to be able to get the indexes from the highlighted text.

I think that I have a workable idea. I'm going to be trying this today, and I'll let you all know how it goes. I've read up on the 'Change' event properties... I think that if I can just find a way to programatically overwrite the selection on the exit event, that will trigger the on change event... then in the change event, check to se if the 'changed' property contains the value that was used on exit. If it was, restore the prevtext, then capture the selstart/selend to be used in formatting.

The only issue with this that I can see is how to programatically overwrite the selection on exit to trigger the change event.

I'll be playing with this until I get it, or until I finally admit defeat. I would appreciate any help or thoughts that anyone may have to offer. If I manage to get this working, I'll provide a custom control containing the rich text field and the formatting controls.

And yes, I know about the formatting controls that are inherant within acrobat, but my users want more that what has been provided... and they don't like that the toolbar can 'disappear' on them. Having it on the form, just above the text field would make them happy.

Thanks again to everyone who has been replying.

- Scott