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

How to use jquery plugins in node templates? #375

Closed
vphelipe opened this issue Mar 16, 2022 · 3 comments
Closed

How to use jquery plugins in node templates? #375

vphelipe opened this issue Mar 16, 2022 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@vphelipe
Copy link

I'm trying to use selectize.js on a node. To insert by dragging I did it like this:

  case 'saved message':
      var idOfElement= Math.random().toString(36).substr(2, 11).toUpperCase();
        var savedmessage = `
        <div>
          <div class="title-box"><i class="fab fa-telegram-plane"></i>Saved message</div>
          <div class="box">
            <p>Select the message</p>
            <select id="`+idOfElement+`" df-salvages>`+
            '<option value="">' + languages['msgauto3'][lng] + '</option>';

        myarray.forEach(function (contact) {
            savedmessage += '<option value="'+contact.id+'">'+contact.name+'</option>'
        })

        savedmessage += `</select>
          </div>
        </div>`;
        editor.addNode('savedmessage', 1, 0, pos_x, pos_y, 'savedmessage', { "saved": 'channel_3'},savedmessage );

        $('#'+idOfElement).selectize({
            maxItems: 1,
            plugins: ['remove_button', 'restore_on_backspace'],
            onChange: function(value) {

                var event = new Event('input', { });

                var element = document.getElementById(iddotrem);
                element.dispatchEvent(event);

           }
        });
        break;

It's not a very elegant way, but it worked. But I'm not sure how to initialize selectize when I use editor.import().
Is there any way I can do this?

@jerosoler jerosoler self-assigned this Mar 17, 2022
@jerosoler jerosoler added the question Further information is requested label Mar 17, 2022
@jerosoler
Copy link
Owner

Use the events.

In this case you can use the import event.

editor.on('import', function(import) {
  console.log(import);
  /** YOUR CODE **/
})

Maybe you could also do the same with nodeCreated.

editor.on('nodeCreated', function(id) {
  console.log("Node created " + id);
  /** YOUR CODE **/
})

@vphelipe
Copy link
Author

Thank you for your help! Using the events I was able to change what I wanted. Now I have another question: I need to change the node's html, because the select values can change, I can change the values at runtime, but the node's html remains intact and when I import it, it cannot select a value which does not exist in the saved html. Please what way can I use to change node's html?

@jerosoler
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants