1

To preface this, I'm using CiviCRM's integration on Drupal 7, with the Webform integration module.

I'm looking to store a number of custom fields as a year. It appears that I am able to use the Date field type to store a date in the format of "YYYY", which sounds like what I want to do. However, the widget that is presented to the user to input the data requires you to choose a specific date from a date picker rather than a year, even if it only stores the year.

On top of that, when I use the Webform module integration with CiviCRM, the widget that I am presented with has 3 dropdowns, one for month, one for day, and one for year.

Ideally both the backend widget and the Webform widget would simply be a select box that allows you to pick only the year starting about 60 years back and ends 20 years in the future. I'm sure I could just make a select box to do just that, but I don't want to manually edit the values in a select box just to get a simple date field.

Does anyone know if there is a way to handle this the way I'm describing or am I stuck using a full date field to simply store a year?

1

You can achieve this in Webform by hiding the day and month fields as well as deselecting the enable pop-up calendar option on the webform component. There you can also set how far back you'd like the years to go.

However, Civi still stores the entire date. I believe the date will be stored as Today's date, 2015 12:00 am if you select 2015 for example.

  • It looks like I can do that when adding a new non-CiviCRM field, but for some reason it looks like I don't have the ability to edit components that are tied to CiviCRM. I thought maybe they couldn't be edited if they had data attached to them but I went and cleared my test submissions but it still didn't put the edit button next to them in the Webform tab. Am I doing this wrong or something? – A.J. Nov 20 '15 at 20:22
  • Scratch that. Found out that I'm just a version behind based on this: civicrm.stackexchange.com/questions/7541/… Using a newer version made the edit links show up. Thank you, sir! – A.J. Nov 20 '15 at 20:29
1

I think "year only" widgets could be improved in CiviCRM. Until that happens, you might be better off with a custom field of type "number".

In the webform you can specify a minimum and maximum amount to limit it to reasonable years.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.