事件显示触发时,弹出窗口中的Bootstrap Datepicker清除其他输入

Pav*_*nko 2 javascript asp.net bootstrap-datepicker

我在弹出窗口中有一个表单,在此表单中,我输入了datepicker引导程序。我在输入之前用datepicker填充所有输入,但是当我打开datepicker时,所有输入将清除。有人可以帮忙吗?

    $('.datepicker').datepicker({
        format: 'dd.mm.yyyy',
        language: 'ru',
        autoclose: true
    });
Run Code Online (Sandbox Code Playgroud)
<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">&times;</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>
Run Code Online (Sandbox Code Playgroud)

小智 7

如果有人仍然需要它:

并非总是可以使用显示和隐藏事件而不是显示和隐藏事件。更好的解决方法是检查事件名称空间:

modal.on('show.bs.modal', function(e) {
    if (e.namespace === 'bs.modal') {
        //
    }
});
Run Code Online (Sandbox Code Playgroud)

来自https://github.com/uxsolutions/bootstrap-datepicker/issues/978