0

I'm trying to change the title of a converse.js chat box that opens when sent a new message.

I've got the id of the pop-up chat window stored in a variable chatbox_id, and I'm trying to use jquery inside an ajax success function to de-reference that variable and set the "chat-title" text field, but the syntax I have is not correct:

converse.plugins.add('name_lookup', {
        initialize: function () {
          var _converse = this._converse;
          _converse.on('pluginsInitialized', function () {
          _converse.on('chatBoxInitialized', function (chatbox) {

          var title = chatbox.model.attributes.fullname;
          var chatbox_id = chatbox.model.attributes.box_id;
          var data;


            $.ajax({
                    type: "POST",
                    url: 'lookup.php',
                    async: false,
                    data: "number=" + num_title[1],
                    success: function(data, status, xhr) {                                                      
                     chatbox.model.attributes.fullname = data;
                     $('#' + chatbox_id).children('chat-title').text(data);
                    }
                  });

I've tried other syntactical routes such as:

$('#' + charbox_id + ' chat-title').text(data);

along with

$('#' + charbox_id).children('chat-title').text(data);

But none seem to work. I'm sure I'm missing something obvious here, but Googling for such things as "use jquery to set nested div tag using a variable for parent id" yielded the attempts above.

If there is a conversejs helper function to set the chat-title value in the model, and have converse automatically manage refresh of the chatbox title text, that would be great too.

Any help appreciated.

rotor155
  • 53
  • 7
  • You looking for the **element** `chat-title` of `#{the chatbox}` (I assume you meant chatbox not charbox). I guess that there is no element `chat-title` but a div with the class `chat-title`. If it is the case use `$('#' + chatbox_id + ' .chat-title')` (notice the dot before `chat-title`). – Fathy Nov 25 '17 at 19:35
  • Fathyb - Thanks for your comment. You are indeed correct... chat-title is indeed a class. Unfortunately, the proposed addressing scheme doesn't seem to be access it. To be sure, chat-title is a NESTED class farther down from chatbox_id, so not sure if that effects the syntax at all, – rotor155 Nov 26 '17 at 07:21

1 Answers1

0

ok, figured it out;

After making changes to the chatbox item, such as

chatbox.model.attributes.fullname = data;

then you need to re-render

chatbox.render();

Hopefully this will help someone going forward.

rotor155
  • 53
  • 7