New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hide datetime time field element by default #637
base: 2.x
Are you sure you want to change the base?
Conversation
c3f4412
to
5213b6c
Compare
Reposting here what I posted in the Matrix chat... I'm trying to understand the consequences of #635 and #637 together in terms of the ordering of things like movements... It seems like although the ordering would still work (by falling back on the order of the log ids), it would end up being less intuitive because it users wouldn't see the obvious "this log occurs after this other log" relationship as clearly. I think it is still valuable to set the time in many scenarios even when the user mostly "doesn't care" about it. Another problematic scenario is when the user selects a date in the past for a new log - because it is probably unintuitive for that log to (by default) "come before" other logs on that date. (All this is assuming I'm understanding the effects of those changes correctly.) |
I responded in chat (let me know if I missed anything or there are still questions @symbioquine!). Copying some of the point here for posterity:
|
I copied two relevant quotes from users into the PR description above for reference. |
It's probably important to emphasize that this doesn't change current behavior of the date/time fields at all. It still loads the forms with a time of either I chose the string "Show time" because I think that is the simplest, while still conveying that the time is there... it's just hidden. One thing that still needs to be done (meant to but forgot) is wrap the "Show time" string in the Drupal JS translation function, so it gets translated properly. |
This PR would exacerbate the issue described in #625 - so we might want to think about a solution to that at the same time. Basically: there is an existing UX issue where "optional" (non- |
Quick notes from call w/ @paul121 (some related to this, some semi-related):
|
I've added a
This fixes a couple bugs I found. One is that hard-coding Also, I believe as currently implemented this JS behavior would effect all datetime form elements on the page, not only specific ones... by targeting the
I added some logic for this, but unfortunately it only works for the This also brings up an issue with how I've implemented things:
Still not quite sure how we can fix this... I didn't spend much time looking at this but not sure how we can modify the submit logic for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @paul121! These are great next steps. Still more to do, but it's getting closer!
I tested locally and these changes serve to target the following cases:
- Planting quick form
- Animal move/group action forms
The cases that it does not cover are:
- Log form timestamp fields
- Log clone/reschedule action forms
FarmFieldFactory
timestamp fields that are not required (eg: Animal birthdate) - because the time is empty by default, so$existing_time_midnight
isFALSE
(although this relates to "automatically set time to 0s if date is filled on submit (fixes Date format error on test logs. #625)")
This also brings up an issue with how I've implemented things:
farm_field
would have a dependency onfarm_ui_theme
.
I see what you mean. We certainly can't have low-level modules depending on UI modules. Moving it down to farm_field
might make sense - at least as a first step. It feels weird to me because that introduces UI logic in a low-level module - but farm_field
is a bit weird in that regard because it does make UI decisions about field widgets etc. And most higher-level modules already depend on it (directly/indirectly including the three affected by your changes: farm_location
, farm_group
, farm_quick_planting
).
If we moved it to farm_field
it would mean that it becomes impossible to disable this behavior in core elements, though. Maybe that's OK?
I don't love the fact that it would add a bunch of new files to farm_field
just for this UI enhancement, though (farm_field.libraries.yml
, farm_field.module
, datetime_toggle.css
, datetime_toggle.js
).
What about this (thinking from the other direction): could we make the "toggle time" behavior default to TRUE
? And apply it to all datetime
elements that DON'T explicitly set #toggle_time
to FALSE
? I'd have to take a closer look to see how that would work, but maybe it would just require a bit of refactoring of the JS? And we could remove all the `'#toggle_time' => TRUE's?
automatically set time to 0s if date is filled on submit (fixes #625)
Still not quite sure how we can fix this... I didn't spend much time looking at this but not sure how we can modify the submit logic for thedatetime
form element without creating our own. Maybe a custom#value_callback
or#process
callback?
I think we should figure this out before merging, either in this PR or another one, because it is indirectly related and these changes will exacerbate #625.
Hmm...
$form['toggle_time'] = [ | ||
'#type' => 'checkbox', | ||
'#title' => $this->t('Toggle time'), | ||
'#description' => $this->t('Default to time input hidden with a button to show time input.'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor tweak to make this language a bit clearer?
Default to time input hidden with a button to show time input.Hide the time input by default, with an option to show it.
@@ -0,0 +1,22 @@ | |||
(function (Drupal, once) { | |||
Drupal.behaviors.farm_ui_datetime = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Rename to Drupal.behaviors.farm_ui_datetime_toggle
?
I think this would cover the "Log form timestamp fields" and "Log clone/reschedule action forms"... ? |
I think we should avoid this. It would modify datetime form elements everywhere, being used by core or any other module. This would be a convenient way to solve the log timestamp and log action forms but I think there are too many other unknowns. As an example: the Rothamsted quick forms use datetime and expect the user to enter a time value. I'd be happy to add a |
Makes sense. If we move this stuff to Tricky tricky. |
I suppose we could alter the |
Or at least the "low-level" ones, like |
We could do all the alters... But this seems like a good reason to keep it as a lower level dependency and avoid that complexity! I see Would still need to alter anything provided by the log module. But if we move all of this core functionality into out of One step further, I'm curious about providing a custom datetime form element altogether like
But we need to think of what downsides there might be to this. Things that come to mind are added maintenance & losing any other potential alters that target the |
This is something I've proposed a number of times in the past, and now that #635 has been merged it became easy to sketch up a proof of concept for consideration.
The idea is: on
datetime
fields, hide the "time" field by default, and replace it with a small "Show time" link.Before:
After:
(clicking "Show time" causes it to look like the "Before".)
This would affect all
datetime
form elements, including the timestamp field in log edit forms, the planting quick form, and the bulk action forms.This is a simple change, but I think it serves to improve UX in a few subtle ways. It makes the UI cleaner/simpler for broad cases where time isn't necessary most of the time (eg: cloning/rescheduling logs, planning animal movements and plant seeding/transplanting/harvest, etc), but it still allows specifying the time in a more granular way when necessary.
Here are two places this idea was mentioned in the past:
Quotes from users:
https://farmos.discourse.group/t/reduce-date-time-entry-to-date-only-entry/415
https://farmos.discourse.group/t/reduce-date-time-entry-to-date-only-entry/415/2