Purpose
- Support empty time range values
Designed User Experience
- A user has already configured a field for time range and is editing content (in my example "event")
- When editing the time range field sometimes end times are not known so the user should be able to enter only a start time
- Once the user clicks save only the start time should show
Possible Bug Fixed
- Currently when the user clicks save with only the start time the current time is displayed, this issue will fix this behavior and support empty values
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | time-error.png | 16.9 KB | jan-e |
| #10 | time_field-support-empty-time-range-3074674-10.patch | 3.7 KB | generalredneck |
| #5 | support-empty-time-range-3074674-5.patch | 3.93 KB | ccjjmartin |
| #2 | support-empty-time-range-3074674-2.patch | 3.74 KB | ccjjmartin |
Issue fork time_field-3074674
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ccjjmartin commentedComment #3
ccjjmartin commentedI am thinking there are probably better ways to handle this then picking the number 86401 (one second after 24 hours). I would love some feedback from the community on other approaches here.
Comment #4
ccjjmartin commentedComment #5
ccjjmartin commentedComment #6
ccjjmartin commentedAdded another possibility which is to allow the time separator to be removed when only a single time is displayed.
Comment #7
labboy0276 commentedThis works well when you don't have an end time. Thank you for this.
Comment #8
bramdriesenCare to elaborate the int 86401 ?
Comment #9
bramdriesenComment #10
generalredneckRerolling the patch done by ccjjmartin. I know that it works but I don't understand all the logic either.
86401 is Friday, January 2, 1970 12:00:01 AM GMT. I'm not sure what the need is there but probably could help figure that out at some time. Likely some random value that will never be used that's in the past that can be validated against since the date widget select something?
Comment #11
ccjjmartin commented@generalredneck I picked a value that would not normally be used. So 60 seconds * 60 minutes * 24 hours = 86400 seconds in a day.
I then added 1 to that value so that I knew it wasn't a valid value but could still be referenced. Probably better ways to do it but that was the original thought process.
Comment #12
nickdickinsonwildeWorks good and I think the 86401 is a reasonable value
Comment #13
bramdriesenThe only thing we are missing now is an automated test to verify this functionality :)
Comment #14
nagy.balint commentedI also needed this patch.
It seems to work fine!
Comment #15
xaa commentedhi, thank you generalredneck. It seems I also need patch in #10 after a d9.4.8 > d9.5.11 update, possible?
When trying to access a node the patch from #10 solves the error
"InvalidArgumentException: Provided value is out of range. in Drupal\time_field\Time::assertInRange() (line 64 of modules/contrib/time_field/src/Time.php)".
The node edit page was also broken (impossible to access/edit the node). Should I open a new ticket for this report ? (as it may need more attention and a higher priority level as the error fully broke the access to the /node/xx/edit page).
Comment #16
bramdriesenI'll be trying to make the tests
Comment #17
bramdriesenJust noticed that this patch actually completely bypasses the field validation. If you set the field as required you can simply save without entering any value at all...
Comment #19
bramdriesenAdded kernel test
Comment #21
bramdriesenComment #23
jan-e commentedAfter the update from 2.1.0 to 2.1.1 I am getting this error during a cron:
A few lines of the stack trace:
Looks like the same error as in #15. I am running Drupal core 10.2.3. And reverted the update to 2.1.1 for now.
Comment #24
bramdriesen@Jan-E What is the value you're trying to submit?
Comment #25
jan-e commented@BramDriesen I really would not know. It also happened when a cron was invoked from outside the site.
Comment #26
jan-e commentedThis was the first time it happened, on a time that almost nothing was done on the site:
Comment #27
bramdriesenI've been testing this for a bit but I can't seem to reproduce it :/ if you would happen to be able to debug a bit and see what the values are/where they come from that would help.
Comment #28
jan-e commented@BramDriesen thanks for getting back on this.
I just had this once again. Somehow the exact value 86401 gets entered in a time field. When cron runs it apparently tries to clear up the entity cache and falls into the error.
The previous occasion I remedied it by manually deleting the field instance and the revision instance from the database. I will try to change the value into 86400 now. And will try to find out how users manage to enter 86401.
Comment #29
bramdriesenI think there is someone else with a similar issue in #3423941: After 2.1.1 update all time fields are treated as required; empty values not accepted.