You are here

function date_views_select_validate in Date 8

Same name and namespace in other branches
  1. 7.3 date_views/date_views.module \date_views_select_validate()
  2. 7.2 date_views/date_views.module \date_views_select_validate()

Validation hook for exposed filters that use the select widget. This is to ensure the the user completes all parts of the date not just some parts. Only needed for the select widget.

1 string reference to 'date_views_select_validate'
date_views_filter_handler_simple::value_form in date_views/includes/date_views_filter_handler_simple.inc
Add the selectors to the value form using the date handler.

File

date_views/date_views.module, line 375

Code

function date_views_select_validate(&$form, &$form_state) {

  // If there are no values just return.
  if (empty($form['value']) && empty($form['min'])) {
    return;
  }
  $granularity = !empty($form['min']['#date_date_format']) ? date_format_order($form['min']['#date_date_format']) : date_format_order($form['value']['#date_date_format']);
  $filled = array();
  $value = drupal_array_get_nested_value($form_state['input'], $form['#parents']);
  foreach ($granularity as $part) {
    if (!empty($value['value'][$part])) {
      $filled[] = $part;
    }
  }
  if (!empty($filled) && count($filled) != count($granularity)) {
    $unfilled = array_diff($granularity, $filled);
    foreach ($unfilled as $part) {
      switch ($part) {
        case 'year':
          form_error($form['value'][$part], t('Please choose a year.'), $form_state);
          break;
        case 'month':
          form_error($form['value'][$part], t('Please choose a month.'), $form_state);
          break;
        case 'day':
          form_error($form['value'][$part], t('Please choose a day.'), $form_state);
          break;
        case 'hour':
          form_error($form['value'][$part], t('Please choose an hour.'), $form_state);
          break;
        case 'minute':
          form_error($form['value'][$part], t('Please choose a minute.'), $form_state);
          break;
        case 'second':
          form_error($form['value'][$part], t('Please choose a second.'), $form_state);
          break;
      }
    }
  }
}