@Html.EJS().DateTimePicker("datetimepicker").Width("250px").Open("onOpen").Render()
<script>
function onOpen(args) {
this.footer.querySelector('.e-today').addEventListener('click', function () {
var dateTimeInstance = document.getElementById("datetimepicker").ej2_instances[0];
dateTimeInstance.value = new Date(new Date().toLocaleString());
});
}
</script>
|
When using this solution change is triggered twice. Once to set the date and a second time setting the time. Is there a work around?
Code Example:
@(Html.EJS().DateTimePickerFor(model => model.DateField)
.Open("onOpen")
.Change("change")
.ShowTodayButton()
.Placeholder("Select date and time dropped")
.Render())
<script>
function onOpen(args){
this.footer.querySelector('.e-today').addEventListener('click', function () {
var thisInstance = this.inputElement.ej2_instances[0];
thisInstance.value = new Date(new Date().toLocaleString());
});
}
function change(args){
console.log("value: " + args.value)
}
</script>
Console...
value: Tue Aug 02 2022 00:00:00 GMT-0500
value: Tue Aug 02 2022 09:32:35 GMT-0500
Hi Matt,
In DateTimePicker component the Change event will triggers for both Date and Time value get changed or either selected in calendar or time popup. This is the intended behavior of our component.
Regards,
Udhaya Kumar D