Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS Error: "Tribute was already bound to TEXTAREA" #31

Closed
wacochili opened this issue Aug 31, 2016 · 4 comments
Closed

JS Error: "Tribute was already bound to TEXTAREA" #31

wacochili opened this issue Aug 31, 2016 · 4 comments

Comments

@wacochili
Copy link

wacochili commented Aug 31, 2016

I'm having issues triggering @mentions with an app using Rails 5, Ruby 2.3.1 inside a Backbone model in a Marionette view.

In my view, I have a form in a modal with a textarea: <textarea name="message" rows="3" placeholder="Write your comment..." class="form-input"></textarea>.

On keyup with '@' in console I am getting the above error: "Tribute was already bound to TEXTAREA".

The code in my Marionette view is pretty simple, the following is my function (in CoffeeScript):

mentionedUsers: ->
      allBrandUsers = (app.BrandChannel.request 'current:brand:users')
      tribute = new Tribute(values: allBrandUsers.models)
      tribute.attach(@ui.message)

...where @ui.message is the name of the <textarea>

I'm attaching the function with an event (last line below):

events:
      'submit @ui.form': 'onBeforeSubmit'
      'keypress @ui.message': 'onMessageKeypress'
      'keyup @ui.message': 'mentionedUsers'

With debugger stepping through, allBrandUsers evaluates properly:
UsersCollection {length: 2, models: Array[2], _byId: Object, parent: BrandModel}

also tribute evaluates properly:
Tribute {menuSelected: 0, current: Object, inputEvent: false, isActive: false, menuContainer: null…}

attaching seems to evaluate properly (although I am curious about the array here):
[<textarea name="message" rows="3" placeholder="Write your comment..." class="form-input" data-tribute="true"></textarea>]

I do not get the dropdown to trigger at all, and additionally, there's the error in console I mentioned already.

screen shot 2016-08-31 at 9 03 50 am

@mrsweaters
Copy link
Collaborator

mrsweaters commented Aug 31, 2016

The issue is that on key up you are rebinding to the same element on the page. The library adds a data-tribute attribute to the element to let you know that you are potentially double binding events.

What I would do is bring the instantiation of the Tribute instance, and attachment to the element, outside the scope of the event listener. You are also doing a request for allBrandUsers data for every key up event. I don't recommend doing this as this will put an unnecessary load on your server and the page. You might not need the key up listener at all from what I can tell.

@wacochili
Copy link
Author

Thanks for the feedback. Based on your suggestions, this is fixed and there is no error with tribute. This is user error. The allBrandUsers is cached once as a variable and then referenced, so no issues there.

My data collection was structured incorrectly and all is well. Closing.

@mrsweaters
Copy link
Collaborator

I'm glad you got it working! Let me know if you have any other issues.

@devhassanconcept
Copy link

devhassanconcept commented Mar 8, 2021

can you tel how u used it for first textarea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants