Expand my Community achievements bar.

Clear text selection on focus

Avatar

Level 1

Hi

I'm developing an interactive form in LiveCycle Designer, where I need to use setFocus in certain circumstances. The problem is that when I use setFocus, the text in the field I'm setting focus to, gets selected. Is there any way to deselect the selected text and place the cursor after the text in the field? Or is this just default behavior in a pdf?

2 Replies

Avatar

Level 10

Hi,

this behaviour cannot be changed.

The text is always selected when you enter a field.

If the text fields already contains a text string that should not be deleted you can use a script in the change event of that field.

It will modify the text selection coordinates so you can add additional text to your field even if the whole text is selected.

if (xfa.event.change.length > 0 && xfa.event.selStart === 0 && xfa.event.selEnd === (xfa.event.prevText.length)) {

xfa.event.selStart = xfa.event.selEnd = xfa.event.prevText.length;

}

Avatar

Level 1

Hi,

Thanks for the help. It wasn't exactly what I was looking for, but seen as what I was looking for isn't possible, this will do nicely.