我在弹出窗口中有一个表单,在这个表单中我输入了datepicker bootstrap。我在输入datepicker之前填充所有输入,但是当我打开datepicker时,所有输入都清除了。 有人可以帮忙吗?
$('.datepicker').datepicker({
format: 'dd.mm.yyyy',
language: 'ru',
autoclose: true
});

<div class="modal fade" id="taskform" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Создать задачу</h4>
</div>
@using (Html.BeginForm(Model.ActionName, Model.ControllerName, FormMethod.Post, new { id = "task_form" }))
{
<div class="modal-body">
<div class="form-group">
@Html.HiddenFor(m => m.CampaignId)
@Html.HiddenFor(m => m.AuthorId)
@Html.LabelFor(x => x.Title)
@Html.TextBoxFor(x => x.Title, new { @class = "form-control form-input" })
</div>
<div class="form-group">
<br />
@Html.LabelFor(x => x.Description)
@Html.TextAreaFor(x => x.Description, new { @class = "ckeditor form-control form-input", rows = "3" })
<br />
</div>
<div class="form-group">
@Html.LabelFor(x => x.DeadLine)
@Html.TextBoxFor(x => x.DeadLine, new { @class = "form-control form-input datepicker", placeholder = "Дедлайн" })
<br />
</div>
</div>
<div class="modal-footer" style="text-align: left;">
<button type="button" id="task-submit" class="btn btn-primary" style="float: right;">Создать</button>
@Html.DropDownListFor(m => m.Performers, Model.AllPerformers.Select(item => new SelectListItem()
{
Text = item.FullName,
Value = Convert.ToString(item.Id)
}), new { @class = "form-control select2 ", style = "", multiple = "multiple", placeholder = "Добавьте исполнителей" })
</div>
}
</div>
</div>
</div>
&#13;
答案 0 :(得分:5)
如果有人仍然需要它:
使用显示和隐藏的事件而不是显示和隐藏并不总是可行的。更好的解决方法是检查事件名称空间:
modal.on('show.bs.modal', function(e) {
if (e.namespace === 'bs.modal') {
//
}
});
来自https://github.com/uxsolutions/bootstrap-datepicker/issues/978
答案 1 :(得分:0)
我尝试复制你的问题但是我的表单在点击日期选择器时没有清除其他输入。
查看:
<button type="button" class="btn btn-primary" id="btnAdd" data-target="#modalTaskForm" aria-label="Left Align">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add Task
</button>
<!-- Add Modal -->
<div id="modalTaskForm" class="modal fade" role="dialog">
<div class="modal-dialog modal-sm">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Task Form</h4>
</div>
<div class="modal-body">
@using (Html.BeginForm("PopOver","Home", FormMethod.Post, new { id = "task_form" }))
{
<div class="modal-body">
<div class="form-group">
@Html.HiddenFor(m => m.CampaignId)
@Html.HiddenFor(m => m.AuthorId)
@Html.LabelFor(x => x.Title)
@Html.TextBoxFor(x => x.Title, new { @class = "form-control form-input" })
</div>
<div class="form-group">
<br />
@Html.LabelFor(x => x.Description)
@Html.TextAreaFor(x => x.Description, new { @class = "ckeditor form-control form-input", rows = "3" })
<br />
</div>
<div class="form-group">
@Html.LabelFor(x => x.DeadLine)
@Html.TextBoxFor(x => x.DeadLine, new { @class = "form-control form-input datepicker", placeholder = "Дедлайн" })
<br />
</div>
</div>
<div class="modal-footer" style="text-align: left;">
<button type="button" id="task-submit" class="btn btn-primary" style="float: right;">Создать</button>
</div>
}
</div>
</div>
</div>
</div>
<!-- /.modal -->
脚本:
<script>
$(document).ready(function () {
$('.datepicker').datepicker({
format: 'dd.mm.yyyy',
language: 'ru',
autoclose: true
});
});
$(document).on('click', '#btnAdd', function () {
$("#modalTaskForm").modal();
});
</script>
答案 2 :(得分:0)
尝试此代码
$("#my-datepicker").datepicker().on('show.bs.modal', function(event) {
// prevent datepicker from firing bootstrap modal "show.bs.modal"
event.stopPropagation();
});