I have added Bootstrap 3 eonasdan-datetimepicker. When I Select Datetimepicker it gives focus to that particular Datetimepicker and when i click on submit button, Submit button prevents submitting form and opens datetimepicker-dialog as if it becomes part of datetimepicker
My ViewModel:
[Display(Name = "From")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime From { get; set; }
[Display(Name = "To")]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime To { get; set; }
And View Is:
<div class="form-group">
@Html.LabelFor(model => model.From, htmlAttributes: new { @class = "control-label col-lg-4 col-md-4" })
<div class="col-lg-6 col-md-6">
@Html.TextBoxFor(model => model.From, new { @class = "form-control datetime"})
@Html.ValidationMessageFor(model => model.From, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.To, htmlAttributes: new { @class = "control-label col-lg-4 col-md-4" })
<div class="col-lg-6 col-md-6">
@Html.TextBoxFor(model => model.To, new { @class = "form-control datetime" })
@Html.ValidationMessageFor(model => model.To, "", new { @class = "text-danger" })
</div>
</div>
@section Styles{
@Styles.Render("~/Content/jqueryui")
@Styles.Render("~/Content/datetimepicker")
}
@section Scripts{
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/datetimepicker")
<script type="text/javascript">
$(function () {
//setting datetime picker.
$('#From').datetimepicker({ format: 'DD/MM/YYYY'});
$('#To').datetimepicker({
useCurrent: false, //Important! See issue #1075
format: 'DD/MM/YYYY'
});
$("#From").on("dp.change", function (e) {
$('#To').data("DateTimePicker").minDate(e.date);
});
$("#To").on("dp.change", function (e) {
$('#From').data("DateTimePicker").maxDate(e.date);
});
});
</script>
}