farmOS / field-kit

A modular, offline-first companion app to farmOS.
https://farmOS.org
GNU General Public License v3.0
60 stars 39 forks source link

Support multiple FarmDateTimeForm components on a single page #394

Closed paul121 closed 4 years ago

paul121 commented 4 years ago
paul121 commented 4 years ago

@jgaehring I just added another commit that allows the required property to be false if the provided timestamp is null. This lets me add a "Clear" button to my Date Range form that makes timestamp = null. Without this change the date field would highlight red after clicking "Clear".

Because this all depends on sending the timestamp as null, I don't believe this is breaking in any way. Although it is a rather naive way of making the field optional - is there a better way to make the entire FarmDateTimeForm component optional?

jgaehring commented 4 years ago

Looks great!

Allow the date, hour and minute input fields to be empty if the provided timestamp is null. This improves behavior for forms where the date is optional - currently a null timestamp is displayed as Dec 31 1970 in the form. Once the user provides input, a new timestamp is provided.

So, I'm a little on the fence about this. Originally, the idea was to restrict null or other invalid timestamps because this would be rejected by the server (see #158), but I can see how you wouldn't necessarily want to impose that restriction all the time.

Because this all depends on sending the timestamp as null, I don't believe this is breaking in any way. Although it is a rather naive way of making the field optional - is there a better way to make the entire FarmDateTimeForm component optional?

I think it might be better to have another prop, maybe something like :required="false" but which would default to true. That seems safer to me, but would still allow for flexibility if you wanted to disable it.

jgaehring commented 4 years ago

Added another commit with the required prop. Gonna merge this in and push it out with 0.6.1 (#392).

Thanks @paul121! :clap:

paul121 commented 4 years ago

Great! Thanks @jgaehring !