ivirabyan / jquery-mentions

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

I using for a contenteditable div #68

Open dinhtuvu opened 7 years ago

dinhtuvu commented 7 years ago

example: http://nhadatanbien.com/comment/index.html step 1: type @a and select one in main comment textbox step 2: click to edit a comment step 3: type @a and select one step 4: return main comment textbox and type @a, select one. bug can't get start position

@ivirabyan how to fix this problem? thank you so much

dinhtuvu commented 7 years ago

@ivirabyan, please help!

ivirabyan commented 7 years ago

The problem is that when you click on "edit" button, you initializer mentionsInput not only for the edit form, but for the main comment textbox too, which is already initialized. Repeated calls to mentionsInput on the same field leads to incorrect behaviour. So solution is to initialize specific field, not using a common selector '.comment-content'. Future versions may allow repeated calls to plugin, but now it doesn't.

dinhtuvu commented 7 years ago

@ivirabyan thank for support! yes, I think so. But i haven't a best solutions. I tried follow code:

function resetMention() {
    $('.comment-content[contenteditable=true]').mentionsInput('destroy');

    $('.comment-content[contenteditable=true]').mentionsInput({
        source: [
            {value: 'alex', uid: 'user:1', image :'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xaf1/v/t1.0-1/s200x200/999047_174739439370902_95491054_n.jpg?oh=675da21ca6d5800c70b4fcc02b55ac77&oe=58715BB0&__gda__=1483295654_59c5459aa37caee88017beccb3f215e4'},
            {value: 'andrew', uid: 'user:2', image :'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xaf1/v/t1.0-1/s200x200/999047_174739439370902_95491054_n.jpg?oh=675da21ca6d5800c70b4fcc02b55ac77&oe=58715BB0&__gda__=1483295654_59c5459aa37caee88017beccb3f215e4'},
            {value: 'angry birds', uid: 'game:5', image :'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xaf1/v/t1.0-1/s200x200/999047_174739439370902_95491054_n.jpg?oh=675da21ca6d5800c70b4fcc02b55ac77&oe=58715BB0&__gda__=1483295654_59c5459aa37caee88017beccb3f215e4'},
            {value: 'assault', uid: 'game:3', image :'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xaf1/v/t1.0-1/s200x200/999047_174739439370902_95491054_n.jpg?oh=675da21ca6d5800c70b4fcc02b55ac77&oe=58715BB0&__gda__=1483295654_59c5459aa37caee88017beccb3f215e4'}
        ], 
        suffix: ' ',
        showAtCaret: true
    });
}

but still the same error Error when destroy first times 9015cc1e-a69a-11e6-81c2-a9553bb625a4

Error when destroy next times 77bdda62-a69a-11e6-89f5-c45b010a12ba

ivirabyan commented 7 years ago

It doesn't work because now you're trying to destroy yet uninitialized textareas. You'd better initialize specific textarea which you just opened dynamically. I can't see your code now, so assuming you textarea is a child of <div id="comment123"> you'd select your textarea like this: $('#comment123 comment-content[contenteditable=true]')

dinhtuvu commented 7 years ago

Thanks! My solution is marked for textareas initialize.