3

We want to show multiple dates for the event, each with its own start and stop time.

Day 1
  Start Time #1
  Stop Time #1

Day 2
  Start Time #2
  Stop Time #2

But in custom data (Administer > Customize Data and Screens > Custom Fields), it doesn't seem to be possible to add a field that is just a time without a date.

I realize we could create two fields, each of which contains both a date and a time:

Day 1 Start
Day 1 End
Day 2 Start
Day 2 End

But we'd have to enter each date twice, extra work and introducing an opportunity for errors in entering the redundant information. For each day of the event, we want to enter three items: the date, a start time and a stop time.

2
  • 2
    I see someone requesting this back in 2013, last comment here: issues.civicrm.org/jira/browse/CRM-4520 Apr 14, 2017 at 5:38
  • agreed there is not "time" Data and Input Field Type. And Date does not allow you to have a NULL date component. Could you use a text field and just ensure folks put in data as per your preferred input couldn't you? Not pretty but a workaround?
    – petednz - fuzion
    Apr 14, 2017 at 7:14

1 Answer 1

1

You could create custom text fields, then add these 3 lines of javascript somewhere to your site where it will get loaded on every CiviCRM page:

CRM.$(document).on('crmLoad', function(e) {
  CRM.$('input[data-crm-custom="Event_Time:Start_Time"], input[data-crm-custom="Event_Time:Start_Time"]', e.target).timeEntry();
});

This assumes you've named the custom group "Event Time" and the fields "Start Time" and "End Time". Adjust the code as needed to match the actual names of your fields (while creating/editing an event, right-click on a field and "Inspect" it - in your console look for the data-crm-custom attribute).

The .timeEntry() widget will store the data in human readable format (e.g. 12:53PM). If you prefer it to be stored in a searchable format (so you can sort your events by time, etc) use .crmDatepicker({date: false}) instead of .timeEntry().

Also be careful you don't load this snippet on every page of your website as it will cause an error on non-civi pages due to the lack of CRM variable. hook_civicrm_coreResourceList is a good choice for achieving this.

2
  • Thank you. What will happen if JavaScript is disabled? They would just get a custom text field but without the special formatting? Apr 18, 2017 at 20:59
  • 1
    If js is disabled then CiviCRM is mostly unusable.
    – Coleman
    Apr 19, 2017 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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