ivirabyan / jquery-mentions

Adds mentioning support to your text fields.
http://ivirabyan.github.io/jquery-mentions/
MIT License
114 stars 49 forks source link

Callback for completed insertion #19

Closed JonFabritius closed 9 years ago

JonFabritius commented 9 years ago

I have a situation where my wysiwyg editor (Redactor 10) fails to immediately sync a newly inserted mention into its underlying textarea. The mention result appears correctly in the contenteditable div, but doesn't update in the hidden textarea until a keypress is performed, to add a space, for example.

I tried utilizing ui-autocomplete callbacks, such as close and change, but they seem to be not supported in jquery-mentions? (Or I have bad jquery-fu) On the other end, I tried forcing Redactor to sync. No luck.

The simplest and generally useful fix could be some kind of 'all done' callback for when an item has successfully been inserted into the input? (I can then improvise a sync from there on)

ivirabyan commented 9 years ago

I also use Redactor editor with mentions and had such a problem. Every time a mention is inserted change event is triggered, so you can use it to call sync method on your editor. Here is a snippet from my code, it's CoffeeScript, but should be clear enough:

RedactorPlugins.mentions =
    init: ->
        @$editor.mentionsInput {source: '/mentions/autocomplete/', showAtCaret: true}
        @$editor.on 'change.mentionsInput', (e) =>
            @sync()
JonFabritius commented 9 years ago

Thanks, worked like a charm.