@baris very thanks
This is the JS code I write for new chat with users, thanks to the help you give me
require(['autocomplete'], autocomplete => {
var modal = bootbox.dialog({
title: '[[flags:start-new-chat]]<i class="fa fa-comments-o" style="margin: 0 7px;"></i>',
message: '<input class="form-control input-lg" placeholder="[[user:username]]">',
buttons: {
cancel: {
label: '[[modules:bootbox.cancel]]',
className: 'btn-default',
callback: () => modal.modal('hide')
},
ok: {
label: '[[modules:bootbox.ok]]',
className: 'btn-primary',
callback: () => false
}
},
onEscape: true,
backdrop: true,
show: true
});
modal.on('shown.bs.modal', () => {
var inputEl = modal.find('input');
inputEl.focus();
autocomplete.user(inputEl);
modal.find('.btn-primary').click(() => {
utils.isUserNameValid(inputEl.val()) ? require(['slugify'], slugify =>
$.getJSON(`/api/user/${slugify(inputEl.val())}`, data => {
app.newChat(data.uid);
if (app.user.uid != data.uid) modal.modal('hide');
}).catch(() => app.alertError('[[error:no-user]]'))
) : app.alertError('[[error:invalid-username]]')
});
});
});