converse.js : How can I pre-populate the Username field in the login form

295 Views Asked by At

I have tried this:

<script>
converse.initialize({ 
    websocket_url: 'wss://xxx.xxx.xxx/websocket', 
    jid:'[email protected]',
    show_controlbox_by_default: true, 
    view_mode: 'overlayed' });
</script>

I was hoping this would display a login form with the Username field already populated with the value given in jid. However converse.js still displays an empty field with the default placeholder.

I'm using "https://cdn.conversejs.org/4.0.1/dist/converse.min.js"

1

There are 1 best solutions below

2
On

OK so I'm not a javascript programmer but the solution I've come up with is to modify the renderLoginPanel() function and add the following

    renderLoginPanel() {
      this.el.classList.add("logged-out");

      if (_.isNil(this.loginpanel)) {
        this.loginpanel = new _converse.LoginPanel({
          'model': new _converse.LoginPanelModel()
        });
        const panes = this.el.querySelector('.controlbox-panes');
        panes.innerHTML = '';
        panes.appendChild(this.loginpanel.render().el);
        this.insertBrandHeading();
      } else {
        this.loginpanel.render();
      }

      /* ***Add this line to pre-populate the username field*** */
      document.getElementById("converse-login-jid").value = _converse.jid; 

      this.loginpanel.initPopovers();
      return this;
    },

I'd be interested to hear if this is anywhere near a good solution.