当我在页面上使用JQuery Select2时,它可以正常工作。但是,当它在引导框对话框模式中时,它无法正确显示。
这是我正在使用的jquery代码......
$.ajax({
type: 'GET',
url: src,
success: function (data) {
if (allowed) {
bootbox.dialog({
title: dialogTitle,
message: $('#altForm'),
onEscape: true,
show: false // We will show it manually later
}).on('shown.bs.modal', function () {
$('#enterBtn').hide();
$('#userPwd').hide();
$('.app-ctrl').prop('disabled', true);
$('#altForm').show();
}).on('hide.bs.modal', function (e) {
$('#altForm').hide().appendTo('body');
}).modal('show');
$('.boop').parents('.bootbox').removeAttr('tabindex');
$('.boop').select2();
}
}
});
我相信Select2下拉列表的代码正常工作,因为当我注释掉初始化行时:$('。boop')。select2();选择下拉列表变为常规下拉列表。但我不知道为什么它显示不正确。
答案 0 :(得分:7)
前一段时间我有同样的情况,我设法解决了这个问题:
$request
其中$daylog->user()
是我的bootbox模式对话框。您只需从对话框本身中删除dialog.on('shown.bs.modal', function() {
dialog.removeAttr("tabindex");
});
属性即可。这样它就会按预期工作(就像它在普通页面中工作一样)。
答案 1 :(得分:2)
如果您在" shown.bs.modal"上初始化您的select2组件,我将会工作。方法:
bootbox.dialog({
title: dialogTitle,
message: $('#altForm'),
onEscape: true,
show: false // We will show it manually later
}).on('shown.bs.modal', function () {
$('.boop').select2(); <---- Place it in here!!!
$('#enterBtn').hide();
$('#userPwd').hide();
$('.app-ctrl').prop('disabled', true);
$('#altForm').show();
}).on('hide.bs.modal', function (e) {
$('#altForm').hide().appendTo('body');
}).modal('show');
$('.boop').parents('.bootbox').removeAttr('tabindex');
答案 2 :(得分:0)
var box = bootbox.dialog({
message:"<div class='col-md-4 form-group m-t-menos-15'>" +
" <div class='input-group'>" +
" <label class='control-label' for='motivo'>Motivo</label>" +
" <select class='select-2 motivo_cancela' id='motivo' name='motivo'>" +
" <option> 1</option>" +
" <option> 2</option>" +
" </select>" +
" </div>" +
" </div>",
title: "Cancelamento da viagem",
animate: true,
buttons: {
'confirm': {
label: 'Confirmar',
className: 'btn-info '
},
'cancel': {
label: 'Fechar',
className: 'btn-danger'
}
},
callback: function(result) {
if (result) {
sendPostRequest(
'solicitacaomonitoramento/cancelar',
{id: data.id},
function (xhr) {
BootstrapAlert.success(xhr.msg);
tabelaSolicitacaoMonitoramento.ajax.reload();
},
function (xhr) {
var erros = $.parseJSON(xhr.responseText);
BootstrapAlert.error(erros.erro);
}
);
}
}
});
box.on('shown.bs.modal', function(){
$('.motivo_cancela').select2();
})
答案 3 :(得分:0)
我有同样的错误,这是我的解决方案
on('shown.bs.modal', function() {
$('#estacion').select2({ //includ the function select 2 on show modal
width: "100%",//i put width 100% to show in all the modal
dropdownParent: $('#sistemas')//this is the solucion to show the select options, my select2 is inside a table whit id sistamas
});
})
所有代码
$("#idbutton").on("click", function(e) {
let url = $("#base_url").val() + "example/example/urlBootbox";
$.get(url, {}, function(data) {
modalPrenomina = bootbox.confirm({
title: "Registrar Prenomina",
message: $(data),
size: "middle",
show: false,
buttons: {
confirm: {
label: '<span class="glyphicon glyphicon-floppy-saved" ></span> Guardar',
className: 'btn-sm btn-primary btn-sm'
},
cancel: {
label: '<span class="glyphicon glyphicon-remove" style="margin-right:5%;"></span> Cancelar',
className: 'btn-sm btn-default btn-sm'
}
},
callback: function(result) {
if (result) {
$("#frmPrenomina").submit();
return false;
}
}
}).on('shown.bs.modal', function() {
$('#estacion').select2({
width: "100%",
dropdownParent: $('#sistemas')
});
}).on('hide.bs.modal', function(e) {
}).modal('show');
})
})
HTML 代码
<table class="table table-striped tooltip-demo" id="sistemas" style="margin-bottom: 0px;">
<tbody>
<div class="col-sm-12">
<h3 class="m-t-none m-b"></h3>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class=" form-group "><label class="col-sm-12 col-form-label">Empresa *</label>
<div class="col-sm-12">
<div class="inputGroupContainerfrm inputGroupContainer">
<div class="input-group" id="divSelectE">
<span class="input-group-addon" id="style_spam_empresa"><i class="fa fa-building"></i></span>
<select class="chosen-select" id="estacion" name="estacion" onChange="myChangeEstacion(this);">
<option value="" disabled selected>Elige una opción</option>
<?php foreach ($estaciones as $item) : ?>
<option value="<?php echo $item->id ?>"><?php echo $item->alias ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<br>
</div>
</div>
</div>
<!--
Nota: Se va descomentar esta linea cuando se implemente lo de los departamentos
y se va incluir esta linea dentro de la etiqueta select onChange="revisarDocumento(this);" y se va quitar onChange="myChangeEstacion(this);"
<div class="depa" id="depa">
</div> -->
</div>
</tbody>
</table>