4
I have a textarea where certain text will be typed. This text may contain some specific fields (variable type, which will be replaced later). I need to know how to insert these "variables" in the specific location I need, for example where the mouse cursor was, because all the examples I’ve seen so far only include at the end of the text.
An example of how it should work:
"The [nameClient] is registered in the system since [dataCadastro]"
The words in bold would be the "variables". You need to take the last mouse position because the user can choose where to insert the fields, which simplifies for him.
Additional information: the textarea contains rich text (Ckeditor).
According to the image below, the user selects the "group" (e.g.: personal data, company data, vehicle data, etc.) and then the "fields" combo and populated according to the group (e.g.: personal data => fields: name, age, address, date of birth, etc.). When selecting an item in the "fields" combo, this item will be added in the textarea, exactly at the last mouse location, which can be either at the end of the field or in the middle of the text.
Which version of the ckeditor? If it is the 4, I think that is enough:
CKEDITOR.instances.editor1.insertText( 'texto' );
– Bacco
@Bacco version 4.5
– Danilo Miguel
Tested the above method?
– Bacco
@Bacco, I fixed my test here and actually your suggestion worked - the mistake was mine. That’s exactly what I need, just adapt now to my need (take the value of the field, etc). The important thing that way of doing I have already discovered. Thank you!
– Danilo Miguel