Nugget 14: Search By Date with Two Blazor InputDate Components
This is an enhancement to the same Blazor from previous Nuggets.
This post adds two Blazor InputDate components to the Job Bank application. It does not use an explicit callback mechanism, but property setters in the view model.What Changed in the View
The view contains two InputDate components, each bound to a property in the View Model. This component exposes Value, ValueChanged, and supports @bind-Value.
@bind-ValueChange could be used for a change binding event, less common for Date, but available if needed. Using this binding would require updating the ViewModel interface with a handler.
How MVVMM Helps
We changed the architecture in an earlier Nugget to MVVM, and now it is coming to the rescue! These are how the controls react to user input and can stay in synch. This is the recommended approach for dates. Could the Boolean check boxes be done like this? Of course!
Noteworthy are the control's max/min attribute properties. These attributes are managed by ViewModel FromMax and ToMin string properties so the browser prevents invalid picks and the view model stays consistent.
Note the new properties in the Interface. FromDateTime, ToDateTime, and for min/max, ToMin and FromMax. Also note a new IQueryable<JobPostViewModel> FilteredJobPosts in the interface. This was added to perform the actual date filtering. It could be done better.
The magic to keep the controls in synch happens in the properties.
You read it, this Nugget is getting too long already!
References
Postscript
Oh, dear! I forgot to mention that the QuickGrid is now bound to the new IQueryable<JobPostViewModel> FilteredJobPosts. I am sure you noticed that change is needed in the view.
Comments
Post a Comment