I set up a custom field in CiviCRM to capture a date, so data type of Date and input field type as Select (the pony option available for a Date type) and set the data format as yyyy as I only need to capture the year.
Exposed the field in the Webform, and it gets displayed as a standard three part drop down Date/Month/Year with no apparent means of changing this.
in my case I got round it by changing the custom field to an integer as I knew I would not need to handle the data as a date in this use case, but far from ideal.
Anyone had similar mileage. Maybe I'm missing something obvious.
Comments
Comment #1
colemanw commentedI think the problem is that Webform has no means of showing only a partial date field.
Keep in mind that drupal webform and civicrm are very different systems. This module attempts to bridge those differences and for the most part succeeds, but there will always be little things like this.
Comment #2
colemanw commentedWith a tiny bit of CSS, you could hide the month and day form elements, this is basically what CiviCRM does, since the whole date is actually stored in the db. The only way to store only year is what you've already done - set as type int.
This CSS could be generated automatically by this module, but it isn't a priority for me to work on right now.
Comment #3
colemanw commentedNote that there is no "date time" component in webform, so currently we are mapping those fields to "date" and losing the time aspect.
Comment #4
petednz commentedI think this is a related problem. If someone enters date and then needs to update their submission - when they return to the webform, while all other fields are prepopulated from civicrm the date field shows as blank requiring them to reenter the date. Not ideal.
Is this easily solved?
A useful workaround that may also be beneficial for other use cases would be if we could set it to say that if a field is left blank it does not overwrite existing data - ie use same process as the FILL option when doing an import.
Comment #5
colemanw commentedHi Pete. I believe this bug has been fixed already. See #1373092: Date fields are not correctly displayed anymore (warnings on screen instead).
If you can't upgrade to 2.4 because you're still using Civi 4.0.x, then you can grab a mid-way dev release like the one in #1479522: Backport features from 2.4 to Civi versions prior to 4.1.
Comment #6
colemanw commentedComment #7
colemanw commentedThe lack of date+time has been fixed in 3.0.
As for displaying partial dates, version 3 also allows you to change widget types, so you could change the webform widget while keeping the field as a date in the Civi DB. A textfield widget would work, and with a teeny bit of javascript you could even add a date-popup onto it.
Comment #8
colemanw commentedNo one has stepped up to patch or sponsor this, so marking as won't fix.
Comment #9
upperholme commentedHi Coleman
Coming back to this issue on my latest project.
As suggested in your comment #7 I've tried using a date field in CiviCRM and a textfield widget for the field in the webform. When submitted the page reports an error : "Please enter Date", so I guess this option won't work. It would be great to get this resolved. What's needed?
Comment #10
upperholme commentedWe seem to have found an acceptable approach to working with date fields in CiviCRM and Webform, so thought I'd share it. I'm also aware of patch (https://www.drupal.org/node/336150) for the Webform module that seems to allow the ability to not enter a day, month or year element to any date field in a webform, and this might play nicely with webform_civicrm, but I've not tested it as yet.
Instead we are using default entries in the date fields in the webform, and then hiding the elements we don't need using CSS. The date gets captured without any validation error (as long as the bits of the default date that are not getting edited by the user are within any valid range that might be set for the webform field). And as we are only seeing the bits of the date that we need in CiviCRM, we don't see the default unedited date elements. A little clunky but ut seems to do the job for the moment.