This question is locked. New answers and comments are not allowed.
I have created a view for report having date range from telerik datepicker and not having model for the same.
The code for view is as follow:
<div style="margin-left:200px">
@(Html.Telerik().DatePicker()
.Name("d1")
.Format("dd/MM/yyyy")
.InputHtmlAttributes(new { data_val = "true", data_val_required = "true" })
)
@Html.ValidationMessage("d1", "Please select From Date")<br /><br />
@(Html.Telerik().DatePicker()
.Name("d2")
.Format("dd/MM/yyyy")
.InputHtmlAttributes(new { @class = "check_date" })
)
@Html.ValidationMessage("d2", "Please select To Date greater than from date.")
</div>
<script type="text/javascript">
$(document).ready(function () {
$.validator.addMethod("check_date", function (value, element) {
var d1 = moment($('#d1').val());
var d2 = moment($('#d2').val());
return (d1.format('DD/MM/YYYY')) < (d2.format('DD/MM/YYYY'));
});
});
</script>
However, i can get validation for "d2" date in case this date is smaller than "d1". But unable to get validation message for "d1" date in case it is null. And also in case "d2" is null as well and clicked on button should give both the validation message, but not getting it. So, how can i get the validation message for both the dates in case provided its null.
The code for view is as follow:
<div style="margin-left:200px">
@(Html.Telerik().DatePicker()
.Name("d1")
.Format("dd/MM/yyyy")
.InputHtmlAttributes(new { data_val = "true", data_val_required = "true" })
)
@Html.ValidationMessage("d1", "Please select From Date")<br /><br />
@(Html.Telerik().DatePicker()
.Name("d2")
.Format("dd/MM/yyyy")
.InputHtmlAttributes(new { @class = "check_date" })
)
@Html.ValidationMessage("d2", "Please select To Date greater than from date.")
</div>
<script type="text/javascript">
$(document).ready(function () {
$.validator.addMethod("check_date", function (value, element) {
var d1 = moment($('#d1').val());
var d2 = moment($('#d2').val());
return (d1.format('DD/MM/YYYY')) < (d2.format('DD/MM/YYYY'));
});
});
</script>
However, i can get validation for "d2" date in case this date is smaller than "d1". But unable to get validation message for "d1" date in case it is null. And also in case "d2" is null as well and clicked on button should give both the validation message, but not getting it. So, how can i get the validation message for both the dates in case provided its null.