Since Blazor doesn't support stopping event propagation I need one-way binding for an input element with type="date" and with an onchange event handler.
Something like this:
<input type="date" value="@_endDate" format-value="yyyy-MM-dd" onchange="@EndDate_change"/>
But this doesn't work. The page contains datePicker but without any value.
"_endDate" is of type DateTime.
If I use Two-way binding then everything working fine.
<input type="date" bind="@_endDate" format-value="yyyy-MM-dd"/>
Any idea why the first "input" doesn't work? Is there any mistake or is this a bug in blazor? For plain text one-way binding with onchange event works without problems.
Edit1: _endDate contains the current date and is set as DateTime.Now
protected void EndDate_change(UIChangeEventArgs endDateEvent)
{
_endDate = Convert.ToDateTime(endDateEvent.Value);
StateHasChanged();
}
_endDateand what doesEndDate_changedo? If you check the docs binding is equivalent to setting the new value in the change event. You still have to set_endDateto something if you want it to be displayed - Panagiotis Kanavos