1 date.api.php hook_date_combo_pre_validate_alter(&$element, &$form_state, $context)

Alter the date_combo element before the rest of the validation is run.

Parameters

array $element: The $element array.

array $form_state: A keyed array containing the current state of the form.

array $context: An associative array containing the following keys:

  • field: The $field array.
  • instance: The $instance array.
  • item: The $item array.

See also

date_combo_element_process()

File

core/modules/date/date.api.php, line 173
Hooks provided by the Date module.

Code

function hook_date_combo_pre_validate_alter(&$element, &$form_state, $context) {
  if (!empty($context['item']['all_day'])) {

    $field = $context['field'];

    // If we have an all day flag on this date and the time is empty, change the
    // format to match the input value so we don't get validation errors.
    $element['#date_is_all_day'] = TRUE;
    $element['value']['#date_format'] = date_part_format('date', $element['value']['#date_format']);
    if (!empty($field['settings']['todate'])) {
      $element['value2']['#date_format'] = date_part_format('date', $element['value2']['#date_format']);
    }
  }
}