podio / jquery-mentions-input

MIT License
985 stars 333 forks source link

Convert to mention input if the Text area already has some value #163

Open igniteajaysuwalka opened 7 years ago

igniteajaysuwalka commented 7 years ago

If I already have the markup in textarea then I would want to be converted to Mention input. or else some sort of reset value or set value I need

jaspertandy commented 7 years ago

So I figured this out. Change this line:

https://github.com/podio/jquery-mentions-input/blob/master/jquery.mentionsInput.js#L509

to:

newMentionText = newMentionText.replace(match[0], match[2]);

Otherwise your trigger char doubles up. Then use the defaultValue configuration option when instantiating.

Unfortunately this appears to be the only way to set a custom value programmatically. You could duplicate this method and pass an argument to it, though, if you need it.

https://github.com/podio/jquery-mentions-input/blob/master/jquery.mentionsInput.js#L542-L544

roby65 commented 7 years ago

You can actually change the val method behaviour: val : function (callback) { if (!_.isFunction(callback)) { resetInput(callback); return; } callback.call(this, mentionsCollection.length ? elmInputBox.data('messageText') : getInputBoxValue()); },