Inserting text at cursor position in field

(How) can I insert a text in a field at the position of the cursor?

I am trying to find a function to get the cursor position but can’t find it.

Thanks for your help,

Marcel

Position of cursor is not defined, why whould you need such a thing?

In javascript you can add text directly to dataprovider:
textColumn = textColumn + ‘bla bla’;

or do all kind of string manipulations

Well Jan,

if I make a text-template and want to give the user a possibility to place a tag then it would be very easy to do that at the position of the cursor.

Otherwise the user would add the tag, copy it, delete the old tag and insert it at the appropriate position. A lot of work…

Hope this info helps you to determine if it is something for the feature list. BTW this is standard FM…

Ciao,

Marcel

Additionally the following. The field I want to insert text into is an RTF field. If I use the .concat() function the problem is that the new text is added to the field after the ‘closing formatting’ of the RTF and as such doesn’t show up on screen…

Marcel

In Servoy 1.2 final the text_field and all XXXX_area fields have a method:
elememts..replaceSelectedText(text);
this does the following:
Replace the selected contents (if no selection it will insert at last cursor pos.)

Thanks!

Nice to have the replaceSelection() on fields in RC8 but.. :oops: . I’m not being able to make it work.. can I have an example… please?.

Thank you in advance.

BTW little error: the “move sample” in the replaceSelectedText displays the sample for the getSelectedText

//Returns the current selectedText
var my_text = elements.xx.getSelectedText();

it’s pretty straight forward.(so I would almost think you encountered a bug?)
BTW: it’s working fine on Windows.

//if no text is selected, replacementText will be inserted right after the cursor position.
elements.myField.replaceSelectedText(“replacementText”)

wrong sample move is corrected

Thanks Marteen, Thanks Jan.. that was a quick response… 15 minutes … and during Saturday night.!!!

I found what I was doing “wrong”.. replaceSelectedText() and getSelectedText() works fine on Text_Area.. but do not seems to be working well on Text_Field field.

Yes that is somehow default behaviour.
(also with native components on windows)

When you select some text inside a textfield it will stay selected until it looses focus..

But this will not be easy to fix (because it is default behaviour)

But… Unfortunately I can’t get it to work on OS X10.3.

While doing a selection in the field and calling replaceSelectedText the text is added at the beginning of the (RTF) area. The same behaviour with a text_area…

What I (try to) do is selecting some text in a combobox after placing my cursor in the field…

BTW the placement in the RTF area is done correct after the code so nothing wrong there…