I'm using froala editor to enable my users to create and edit document templates. These templates will be after fed with data and the user defined placeholders shall be automatically filled.
The biggest problem I'm facing at this moment, is that Froala (at least apparently) doesn't provide a way to get the caret position within a <textarea>
or any other HTML element with contenteditable enabled.
Each document template can have many custom fields, and these fields will be shown as options of a <select>
tag that will be above the editor. Always an user select an option, its value will be placed at the position the caret was for the last time and surrounded by curly brackets.
For example:
<select>
<option value='Choose a field'></option>
<option value='lawsuit'>Lawsuit Number</option>
<option value='customer'>Customer Name</option>
</select>
I this case, if the user choose the "Lawsuit Number" option, the text {lawsuit}
should be placed at the position the caret was before the selection.
Does Froala Editor have some built-in mechanism to achieve that? If no, is there another way?