Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi! I think this should be relatively easy to do but I can't figure it out. I have a time field with hours and minutes. I need the minute field to only have options for 00, 15, 30, 45. Showing all 60 minutes is overwhelming. Can someone point me in the right direction?
I know that I could change my time field into two text select boxes, but I like how it says "hour" and "minute" within the select box and this isn't possible to do with just a plain text select box.
Comment | File | Size | Author |
---|---|---|---|
#19 | webform_time_minuteincrements-18.patch | 4.6 KB | benjifisher |
#15 | webform_time_minuteincrements.patch | 4.63 KB | quicksketch |
#9 | minute_increments-434584-comment-9.patch | 2.35 KB | drclaw |
#8 | minute_increments-434584-comment-8.patch | 2.36 KB | drclaw |
Comments
Comment #1
quicksketchNew features are being added to the 3.x version only. I've closed the following issues as duplicates:
#586342: Time increment
#338449: Is it possible to customise the time field?
Comment #2
cbearhoney CreditAttribution: cbearhoney commentedWas this feature added to the 6.x-3.x-dev version? That's the one I have but I don't see any options for increments. Instead I changed the time.inc file to this:
It works, but when a user selects '00' minutes the value is blank in the e-mail. Any idea why?
Comment #3
kthullI don't know about writing patches, but I'm loving the fix suggested in #2. I didn't check the email output, but viewing the webform results shows the double zero in my D6.20 install with Webform 6.x-3.6.
Any chance this can get rolled into dev if it's not already there?
Comment #4
quicksketchWe need a more extensive fix than just hard-coding the minutes in 15 minute increments. We'd need an option when configuring time components to set the increment. I'd be happy to look at patches, but this issue is not a high priority for me.
Comment #5
arlanda CreditAttribution: arlanda commented+1 for this feature via the user interface!
Comment #6
pbosmans CreditAttribution: pbosmans commentedAlso +1 for this feature via the user interface!
Comment #7
Johan den Hollander CreditAttribution: Johan den Hollander commented+1 subscribing...
Comment #8
drclaw CreditAttribution: drclaw commentedThought I would take a stab at this one. Seemed pretty straight forward. Overview of the patch:
- Adds a setting on the time field page to select the minute increments (1, 5, 10, 15,30)
- Validates that the default time's minutes is a multiple of the increment setting
- Uses the minute increment settings to populate the time component options properly on the webform itself
Patch is for 7.x-3.x-dev but should be easily back ported to d6.
Hope it's helpful!
Comment #9
drclaw CreditAttribution: drclaw commentedOops... Sorry, just realized that the patch was for version 3.x-3.9-hotfix. Here's one that will apply to the 7.x-3.x-dev branch. Apologies!
Comment #10
quicksketchNice one @drclaw! I'll review when I get a chance.
Comment #11
drclaw CreditAttribution: drclaw commentedLooking forward to it. =)
Comment #12
Maestro232 CreditAttribution: Maestro232 commentedI definitely need the patch but I'm running D6. Can I apply this same patch?
Comment #13
drclaw CreditAttribution: drclaw commentedI'm not sure if this will apply to the d6 version... Maybe give it a try and see what happens? Otherwise, it's a small patch and should be fairly easy to backport...
Comment #14
quicksketchI'm taking a look at this code now. Overall it looks and works great! It'll need a little bit of tweaking to help make it easily compatible with Form Builder (we'll change the validation function to be on the minuteincrements form element, rather than on the entire form).
Comment #15
quicksketchHere's a patch which takes a slightly different approach:
- Instead of validating the default value, it will simply round the default value to the next valid minute. This bothers the user less and solves problems with using dynamic times, such as "now" as the default value.
- Removed some legacy and cruft code.
- Removed redundant description/help texts.
- Switched to using a FormAPI attribute for #minuteincrements, to make it easily compatible with Form Builder.
Patch seems to apply to D6 and D7 just fine, so no porting necessary. How does this approach sound to you @drclaw?
Comment #16
drclaw CreditAttribution: drclaw commentedNice! I just gave it a whirl and it works perfectly! I like what you did with the time rounding. It works well. =)
Thanks!
Comment #17
benjifisherI do not have time to test (meeting in 10 minutes...) but I looked at the patch.
I suggest replacing this with
A few lines later, I see
Again, I do not have time to test, and I do not have the context, but it looks as though the test should be
Comment #18
quicksketchThanks @benjifisher, both excellent suggestions. Let's refactor and test again.
Comment #19
benjifisherMy second suggestion was half-baked. The code that I quoted is wrapped in
so it should not matter whether you test for strict inequality or not (
>
or>=
).I was not sure how to test the code, so I just set the increment to 5 minutes and added
to the code. It works. My minute field was set to '05'. I did some further testing, and 23:58 gets rounded up to 12:00 pm as expected.
I have attached a patch. The only difference from the one in #15 is my first suggestion from #17.
Comment #20
benjifisherSorry, I did not mean to mark my own patch RTBC.
Comment #21
drclaw CreditAttribution: drclaw commentedCool. Looks good. Just tested it out with no issues. Great suggestion btw. ;-)
Comment #22
quicksketchThanks guys! Tested again and works great. Committed to both 3.x branches of the project. Teamwork ftw!
Comment #24
Scott M. Sanders CreditAttribution: Scott M. Sanders commentedWe would like an option to increment hourly -- in this case, we would probably not need a minutes dropdown at all, just add ":00" to all of the hour options, or as plain text after.