StevenDevooght / tinyMCE-mention

Mention/Autocomplete plugin for tinyMCE WYSIWYG editor.
http://stevendevooght.github.io/tinyMCE-mention/
221 stars 97 forks source link

Insert function can use a different value than the queryBy field. #47

Closed johnnaegle closed 8 years ago

johnnaegle commented 8 years ago

I was using the plugin to display variable names to authors of text templates.

For instance:

"source":[
  {"name":"{{user:first_name}}"},
  {"name":"{{user:last_name}}"}
]

This works well enough for authoring a template, the author types { the variables are shown and replaced using the mentions plugin. 👍

When the template is used, I want the same functionality, but instead of inserting {{user:first_name}} I want it to insert the user's actual name, John. Instead of writing my own insert function, I added an optional value field to the source which gets used on insert:

insertFrom: 'value',
"source":[
  {"name":"{{user:first_name}}", "value": "John"},
  {"name":"{{user:last_name}}", "value": "John"}
]

Now when the insert is performed on a match of {{user:first_name}}, John gets insterted instead.

StevenDevooght commented 8 years ago

Thanks for this one!