<form id="form-element" class="form-vertical">
<div class="form-group">
<ejs-datepicker id='BirthDate' format="MM/dd/yyyy" min="ViewBag.DPMinDate" max="ViewBag.DPMaxDate" placeholder="Selezionare una data"></ejs-datepicker>
</div>
<input type="submit" value="submit" />
</form>
<script>
document.addEventListener('DOMContentLoaded', function () {
var datepickerObject = document.getElementById("BirthDate").ej2_instances[0];
var options = {
rules: {
//must specify the name attribute value in rules section
'BirthDate': { required: true, min: [minDate, 'MIN ERROR!'], max: [maxDate, 'MAX ERROR!'] }
},
customPlacement: (inputElement, errorElement) => {
debugger
//to place the error message in custom position
//inputElement - target element where the error text will be appended
//errorElement - error text which will be displayed.
inputElement.parentElement.parentElement.appendChild(errorElement);
}
};
var formObject = new ej.inputs.FormValidator('#form-element', options);
function minDate(args) {
var inputValue = datepickerObject.globalize.parseDate(args['value'], { format: datepickerObject.format, type: 'dateTime', skeleton: 'yMd' });
if (+inputValue >= +datepickerObject.min.setHours(0, 0, 0, 0)) {
return true;
} else {
return false;
}
}
function maxDate(args) {
var inputValue = datepickerObject.globalize.parseDate(args['value'], { format: datepickerObject.format, type: 'dateTime', skeleton: 'yMd' });
if (+inputValue <= +datepickerObject.max.setHours(0, 0, 0, 0)) {
return true;
} else {
return false;
}
}
});
</script> |