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.
Is there an easier way to create a date with only the month and year? I like the idea of still using the date component but I don't think it is supported — will it be supported in the future? I do not like much the idea of creating separate select boxes for the month and year because I have to rewrite the validation in the date component. Is there other work around here?
(I think I already saw this request but I could not find it - sorry if this is a duplicate)
Comment | File | Size | Author |
---|---|---|---|
#49 | exclude-date-warning-336150-49.patch | 1.09 KB | idflood |
#46 | webform-dmy_optional-336150-45.patch | 9.74 KB | DanChadwick |
#43 | Screenshot from 2014-09-04 14:23:46.png | 33.17 KB | handrus |
#43 | Screenshot from 2014 09 04 14 22 17.png | 110.39 KB | handrus |
#43 | Screenshot from 2014 09 04 14 22 17.png | 110.39 KB | handrus |
Comments
Comment #1
quicksketchNo, it's currently not possible to have a date component without a year. I'm moving this to a feature request. I'm not sure if we'll be able to use the date field provided by core for much longer, as it doesn't have the option for excluding the year either. However Webform already does quite a few tricks with the date field to change the year into a textfield, so I'm sure it'd be possible to remove the year entirely.
Comment #2
primerg CreditAttribution: primerg commentedI think it should be the "Day". Is it also not possible to make the "Day" optional in the component?
Comment #3
machete1 CreditAttribution: machete1 commentedI am looking for this exact functionality as well (not having a Day field). I'm using version 3.6 and it doesn't appear to me that anything like this has been implemented...
I found this issue #121415: Month/Year field type and I am wondering if anyone has tried to implement this code with v3 yet?
Comment #4
jtwalters CreditAttribution: jtwalters commented*ignore this comment*
Comment #5
jtwalters CreditAttribution: jtwalters commented*ignore this comment*
Comment #6
jtwalters CreditAttribution: jtwalters commentedI should test more before attaching these patches... too bad I can't delete previous comments.
This patch should actually save the dates in the database.
Comment #7
monotaga CreditAttribution: monotaga commentedThis is really useful. Any chance we can get this rolled in?
Comment #8
ownage CreditAttribution: ownage commentedI don't know why the status of this topic hasn't been marked, "Needs Review" but it should be. Could someone update this patch to work for the newest versions of Webform?
I'm running 7.x-3.18 and get:
$ patch -p0 < webform_7.x_3.x_optional_day_2.patch
patching file components/date.inc
Hunk #1 succeeded at 21 with fuzz 2.
Hunk #2 FAILED at 89.
Hunk #3 succeeded at 212 with fuzz 2.
Hunk #4 FAILED at 289.
Hunk #5 succeeded at 331 with fuzz 1 (offset 19 lines).
Comment #9
ownage CreditAttribution: ownage commentedComment #10
jtwalters CreditAttribution: jtwalters commentedPatch for optional day and year attached, rewritten for webform 7.x-3.18. Not sure if it's good enough to be reviewed, tested and committed, but it seems fairly harmless and works for me.
Caveat
Comment #11
ownage CreditAttribution: ownage commentedPatching the day as optional should remove the day from appearing in both the form and when viewing the results. Using the patch above, the day continues to show upon reading the results.
I am also getting the error upon editing a submission:
Notice: Undefined index: #attributes in form_process_date() (line 2944 of /includes/form.inc).
Can anyone help out here?
Comment #12
jtwalters CreditAttribution: jtwalters commentedA PHP notice is harmless, but I agree with you that the results view should also hide the optional components. Other than that, does it behave like you expect?
Comment #13
ownage CreditAttribution: ownage commentedYes sir. However, if you or anyone knows of a way to also remove it from the results, please post an update! To allow the calendar on only month & year would be a bonus as well-- right now, the calendar date picker only selects the date once you choose a day. After these two fixes, this could then probably be added into Webform's next release.
Comment #14
jtwalters CreditAttribution: jtwalters commentedUpdated patch as per #13 to also format the results display properly.
Comment #15
ownage CreditAttribution: ownage commentedThanks for the update! I am using it with the Webform Table Element module.
I patched the original date.inc for Webform v7.x-3.18, cleared all caches, noticed you also added in an optional year check box, and upon trying it, the second date input with an optional day continues to give me an error upon submission:
(Which to me, doesn't make sense). I tried changing a value in red after it failed, (once changing the year in red and once changing the month in red) and both times it would submit on the 2nd try. Second attempt showing the results after getting the same behavior below:
As you can see, after both of them were submitted, the results continue to show the day as well.
Comment #16
jtwalters CreditAttribution: jtwalters commentedThanks for trying it out. It looks like I should test more combinations before posting. :) I'll see if I can reproduce the errors and rewrite the patch.
Comment #17
jtwalters CreditAttribution: jtwalters commentedHmm. It looks like there is an incompatibility with my patch and the webform_table_element module. I'll see if I can figure out something.
Comment #18
ownage CreditAttribution: ownage commentedKeep in mind the patch you submitted in #10 worked with the Webform Table Element module without error-- the only issue was that it showed the "Day" in the results still.
Comment #19
jtwalters CreditAttribution: jtwalters commentedThe invalid date error from your optional_day_patch_2_results.png screenshot is probably because February 29th is an invalid date and you couldn't see the day (29) when you submitted the date.
I also need to adjust the patch to trim out [,-/] characters from the date display when optional day/year values are suppressed.
The results page's display issue is probably because webform_table_element overrides webform's built in date theming.
Another related issue is that webform_table_element module does not support required validation on date elements—e.g. if you leave the date blank and the element is required, the standard "this field is required" error is not generated. Without this being fixed, I doubt my patch will be compatible with the webform_table_element module. See #1462386: Validation not working for table element
Comment #20
ownage CreditAttribution: ownage commentedJust a note: the validation is now working for dates in Webform's newest dev version.
Comment #21
jtwalters CreditAttribution: jtwalters commentedI can verify that the date validation is working, however, I believe there is still a bug in webform_table_element display the date fields incorrectly. Ideally, it should use webform's theming so that I won't need to alter the patch to make the dates display correctly.
Comment #22
vishusrinivasan CreditAttribution: vishusrinivasan commented@jtwalters thanks for this cool patch, #14 works and displays on the Month and Year in the results view page, (attached screenshot: 1.png).
There are some issues:
1. The date field is now mandatory even though mandatory is not selected. I am unable to submit the form without selecting a date, this should not be the case.
2. the day appears when I download the submissions in Excel from the results page.
3. And also when displaying the results in a view, the Day appears (attached screenshot: 2.png).
Comment #23
jtwalters CreditAttribution: jtwalters commentedHere's a slight update to the patch. Fixes (1) in comment #22. (can someone verify?)
RE: #22
(1) This patch should prevent date validation on non-required date fields
(2) You will probably have to use Excel to reformat the date display.
(3) In Views you should be able to format date fields with a custom date formatter. See admin/config/regional/date-time in your D7 admin.
Comment #24
vishusrinivasan CreditAttribution: vishusrinivasan commented@ jtwalters, thanks for the patch
#22
(1) is fixed.
(2) Not sure how to do this, the export still shows days for example, when submitted value is Jul 2009 the Excel displays it as 1 July 2009
(3) Not sure if this is a issue with the views, I cannot use custom format for "date fields" used in the webform, but can use custom date formats for "submitted date", "content updated date" etc...
And finally after applying the patch if I enter a correct date the submission and results are fine. but if I enter a random number like 2123, the form is submitted with some error messages (attached webform.png) and no data in the submissions page.
To recreate the steps are:
1. create the webform with date field and day optional.
2. Go to form and select a month and enter 2232 as year (year field is textfield)
3. submit the form.
Comment #25
vishusrinivasan CreditAttribution: vishusrinivasan commentedComment #26
quicksketch@vishusrinivasan: That problem may be solved by this recent change: #1276550: Anonymous users do not use site default timezone. It'll be in the 3.19 and 4.0-alpha4 releases.
No new features are being added to the 3.x branch (which also means we don't need to backport this to D6).
Comment #27
ownage CreditAttribution: ownage commentedIf anyone is using Webform Table Element and wants to make the day optional, I got a hack working to strip it out.
Add this to a block in the administration theme for the results pages using wildcards:
More info here: http://drupal.org/node/1762320
Comment #28
julianmancera CreditAttribution: julianmancera commentedHi all,
I have applied the patch on #14 for a D6 3.18 version of the module but an error pop up, here:
Do you have any clue on how to fix this?
Thank you
Julian Mancera
Comment #29
Albert Volkman CreditAttribution: Albert Volkman commentedAdded on to patch in #23 to include month.
Note, this is for 3.x, and not meant to impede the 4.x progress. Just wanted to share :)
Comment #30
Jerenus CreditAttribution: Jerenus commentedstatus
Comment #31
quicksketchHi guys, thanks for the work on this patch. This is the first time I've had an opportunity to look over the whole thing. Some feedback:
- This patch doesn't seem to affect the downloaded data through CSVs. I think it probably should, but is there a reason to include a full date?
- I'm a little nervous that this isn't really displaying all the data that's being stored. A month/year field isn't really a "date" any more. But I can see the usefulness of this patch and the overall approach looks pretty solid. Nice job.
- All code comments need to be formatted sentence case: starting with a capital letter and ending with a period.
- I'd prefer to make the setting name more representative of what the option does if "day_optional" is TRUE, it really means "day_hidden". It's not optional if you don't have the ability to fill it in.
- Related to the CSV problem, let's abstract this bit out to a dedicated function. This much logic in the theme function isn't ideal:
A related patch that will probably end up affecting this one: #1346536: Make submission date display formats configurable. It doesn't look like this has been updated for 4.x, but I'm not sure many changes are necessary.
Nice looking patch overall. If some of the above things can be addressed I think we can include this in the project.
Comment #32
simon.fryer CreditAttribution: simon.fryer commentedHey guys,
This patch in #29 had a bug in which stopped optional 'day' working. Few minutes digging and found this group of code applying the new defaults on line 74;
+ 'day' => $element['#webform_component']['extra']['day_optional'] ? 1 : NULL,
+ 'day' => $element['#webform_component']['extra']['month_optional'] ? 1 : NULL,
+ 'year' => $element['#webform_component']['extra']['year_optional'] ? $assumed_year : NULL,
Noting the two occurances of 'day' so the functionality would work up until submission, where the form would still error.
+ 'day' => $element['#webform_component']['extra']['day_optional'] ? 1 : NULL,
+ 'month' => $element['#webform_component']['extra']['month_optional'] ? 1 : NULL,
+ 'year' => $element['#webform_component']['extra']['year_optional'] ? $assumed_year : NULL,
Have replaced with the following with new patch attached.
Comment #33
paolomainardi CreditAttribution: paolomainardi commentedUpdate patch #32 to make it compatible with 4.x branch and fixed a typo on #default_value.
Comment #34
paolomainardi CreditAttribution: paolomainardi commentedThere was a typo in my last patch, attached the right one.
Comment #35
handrus CreditAttribution: handrus commentedAbout patch #32 - great patch, just a few comments.
Anyway those few things are fixed on #33 and #34.
You should generate patches from the root of the module. Else it will be harder to apply it.
While you correctly described the fix it still with 'day' instead of 'month'
Comment #36
dcampos CreditAttribution: dcampos commentedThere was an issue in validation when selecting the first date and the month/day were marked as optional.
Now it's fxed with this patch
Comment #37
TBarina CreditAttribution: TBarina commentedPatch in #36 contains:
and consequently
This causes all my date elements in my webforms to become optional even if Mandatory is set in the component since I'm using Beta version of webform.
May I skip this alterations and apply the rest of the patch to get it working in beta or shall I be forced to upgrade to dev versione?
Many thanks in advance.
Comment #38
quicksketchThis patch has not been applied to the project, so you should be able to modify the patch to get it working for you. After you've modified it, please create a new patch with what works for you. Eventually this may get into the project, but there are a number of issues outlined in #31 that haven't been taken care of yet.
Comment #39
xamanu CreditAttribution: xamanu commentedI just rerolled the patch for the 7.x-3.x from #29 to be appliable to the latest stable release (7.x-3.20)
It might be usefull for somebody...
Comment #40
sergiuteaca CreditAttribution: sergiuteaca commentedUpdated #36 patch to make it compatible with 7.x-4.0-rc4 and removed duplicate slashes.
Comment #41
upperholme CreditAttribution: upperholme commentedCould someone summarise what this patch does? I'm unclear, having read through this rather long thread, exactly what the goal is.
Also, is it planned to include it in the main module release?(Just noted comment #31)Comment #42
DanChadwick CreditAttribution: DanChadwick commentedComment #43
handrus CreditAttribution: handrus commentedJust tested #40 and it is working for vast majority of cases.
Just a few notes: The fields are indeed saving the entire data, no matter if it is a day only, month only, year only etc. But IMHO this is the intention of a date field where something is optional. Else it wouldn't be a date anymore. The developer using the data should be aware and threat it accordingly.
The webform results pages display the dates correctly, but the CSV and table don't.
See escreenshots of the scenarios.
Comment #44
DanChadwick CreditAttribution: DanChadwick commentedI looked at this patch some.
I think the component definition and edit form can be worked out.
Conditionals will have to be taken into account, including browser-side and server-side versions.
I believe full dates should be exported to CSV, and certainly must be to Excel.
I don't feel strongly about reporting showing or hiding the suppressed portions of the date, although hiding is preferable.
The displayed submission clearly has to hide the suppressed portions of the date.
The patch above is very American-centric. It makes assumptions about the format and YMD order. http://en.wikipedia.org/wiki/Date_format_by_country
Assuming the above reference is accurate I do not believe that regular expressions can be used to remove suppressed portions of the date and work for all formats in all countries. There are simply too many variants. We do use regular expressions to remove the time from a date/time format, but that's a much easier problem. Times have many fewer formats and are kept separate from the date.
It might be that the best solution is to allow the override of the system-wide format for a particular date field. The user would have to create a date form of the type they want, without the undesired portions. Webform could then see what's missing from the format and omit those from the edit form as well.
Any other ideas?
Comment #45
DanChadwick CreditAttribution: DanChadwick commentedI had some second thoughts. If a format string has its date / month / year formatting characters removed, along with the common extra characters after it (/-.,: ), and then the whole string is trimmed of these characters in case the removed characters were at the end, then the strategy of modifying the format will work.
I adapted the work in #40:
Committed to 7.x-4.x.
Comment #46
DanChadwick CreditAttribution: DanChadwick commentedComment #48
DanChadwick CreditAttribution: DanChadwick commentedComment #49
idflood CreditAttribution: idflood commentedI updated a website to the current dev version of webform and now I have these errors which seems to be related to this issue:
I've attached a very simple patch which fixes these warning.
Comment #50
DanChadwick CreditAttribution: DanChadwick commented@idflood -- Can you give me steps to reproduce this the warnings you are receiving. I don't understand how this is possible, unless some other code (outside of webform) is calling webform_expand_date. Are you using some custom code or other webform-related modules that has something to do with dates?
webform_expand_date is the #process function set in _webform_render_date. It isn't used anywhere else in webform. In _webform_render_date, $element['#exclude'] is always set. Therefore webform_expand_date can rely on it.
I don't want to add additional tests to the codebase unless/until we understand why they are needed. Thanks.
Comment #51
DanChadwick CreditAttribution: DanChadwick commented@idflood -- Any update? Are you still having the error? I'd like to address this before making a release, but I don't know if this is:
Comment #52
DanChadwick CreditAttribution: DanChadwick commentedComment #53
fenstratCommitted and pushed to 8.x-4.x. Thanks!