riganti / dotvvm

Open source MVVM framework for Web Apps
https://www.dotvvm.com
Apache License 2.0
743 stars 97 forks source link

Please support `DateOnly` params in constructors of sub view models or support it for MinDate property of the bp:DatePicker control #1791

Open liviriniu opened 7 months ago

liviriniu commented 7 months ago

Hi,

Currently it crashes if I use a DateOnly parameter in a primary constructor for a sub view model.

The primary constructor: image

The crash log: image

exyi commented 7 months ago

The is that the matching property is of type DateTime. It should work if you also change it to DateOnly

Mar 3, 2024 18:43:09 liviriniu @.***>:

Hi,

Currently it crashes if I use a DateOnly parameter in a primary constructor for a sub view model.

The primary constructor: image.png (view on web)[https://github.com/riganti/dotvvm/assets/63544057/09f12b25-6b26-4828-ab4b-17efe0c012b6]

The crash log: image.png (view on web)[https://github.com/riganti/dotvvm/assets/63544057/bc7898c9-e829-47b7-b1de-7a159378cd55]

— Reply to this email directly, view it on GitHub[https://github.com/riganti/dotvvm/issues/1791], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AB4HNH22QBKDJA4TAXRVOC3YWNOKPAVCNFSM6AAAAABEEEAYYOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGE3DKNBWGY4TINA]. You are receiving this because you are subscribed to this thread. [Tracking image][https://github.com/notifications/beacon/AB4HNH3BAO4FK6MRQ6ODXRLYWNOKPA5CNFSM6AAAAABEEEAYYOWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHICETHIA.gif]

liviriniu commented 7 months ago

Yeees, sure. But... sigh 😿

liviriniu commented 7 months ago

Because then I must do the conversion in the markup for which, by the way, the intellisense does not suggest the ToDateTime method.

image

... I was lazy in giving sufficient context in the issue content.

liviriniu commented 7 months ago

Which, although it makes the markup squiggly warning go away, it crashes with:

image

exyi commented 7 months ago

It wouldn't be hard to add support for the ToDateTime method, but can't you simply change the constructor argument to DateTime? DateTime->DateOnly isn't even implicitly convertible, so the serializer fails legitimately.

(however, BP:DatePicker should just work with DateOnly)

liviriniu commented 7 months ago

BP:DatePicker simply crashes if I use DateOnly

image

but can't you simply change the constructor argument to DateTime?

Sure, this is how I currently go about because I have no choice. I can live with this because although the business logic/layer uses DateOnly as best practice / standard, the points of conversion are small and can get smaller (by encapsulating in an extension method):

image