diff --git a/date_admin.inc b/date_admin.inc index b800201..8f6f2a6 100644 --- a/date_admin.inc +++ b/date_admin.inc @@ -277,6 +277,15 @@ function _date_field_instance_settings_form($field, $instance) { '#weight' => 2.1, '#fieldset' => 'default_values', ); + // Display element description instance setting for date popup. + if ($widget['type'] == 'date_popup') { + $form['show_element_description'] = array( + '#type' => 'checkbox', + '#title' => t('Show date elements description'), + '#default_value' => isset($settings['show_element_description']) ? $settings['show_element_description'] : FALSE, + '#description' => t('Current date (and time) as placeholder if there is no value set.'), + ); + } $form['#element_validate'] = array('date_field_instance_settings_form_validate'); diff --git a/date_popup/date_popup.module b/date_popup/date_popup.module index a03132e..ddce57f 100644 --- a/date_popup/date_popup.module +++ b/date_popup/date_popup.module @@ -317,6 +317,12 @@ function date_popup_element_process($element, &$form_state, $form) { ); } + // Display date element description setting. + if (isset($element['#instance'])) { + $element['#show_element_description'] = isset($element['#instance']['settings']['show_element_description']) ? $element['#instance']['settings']['show_element_description'] : FALSE; + } + $element['#show_element_description'] = isset($element['#show_element_description']) ? $element['#show_element_description'] : FALSE; + $element['date'] = date_popup_process_date_part($element); $element['time'] = date_popup_process_time_part($element); @@ -419,15 +425,10 @@ function date_popup_process_date_part(&$element) { '#ajax' => !empty($element['#ajax']) ? $element['#ajax'] : FALSE, ); $sub_element['#value'] = $sub_element['#default_value']; - // TODO, figure out exactly when we want this description. - // In many places it is not desired. - $sub_element['#description'] = ' ' . t('E.g., @date', array( - '@date' => date_format_date( - date_example_date(), - 'custom', - date_popup_date_format($element) - ), - )); + // Display date element description as placeholder. + if (!empty($element['#show_element_description'])) { + $sub_element['#attributes']['placeholder'] = date_format_date(date_example_date(), 'custom', date_popup_date_format($element)); + } return $sub_element; } @@ -521,16 +522,12 @@ function date_popup_process_time_part(&$element) { $sub_element['#value'] = $sub_element['#default_value']; - // TODO, figure out exactly when we want this description. - // In many places it is not desired. $example_date = date_now(); date_increment_round($example_date, $element['#date_increment']); - $sub_element['#description'] = t('E.g., @date', array( - '@date' => date_format_date( - $example_date, - 'custom', - date_popup_time_format($element) - ))); + // Display date element description as placeholder. + if (!empty($element['#show_element_description'])) { + $sub_element['#attributes']['placeholder'] = date_format_date(date_example_date(), 'custom', date_popup_time_format($element)); + } return ($sub_element); } diff --git a/date_views/includes/date_views_filter_handler_simple.inc b/date_views/includes/date_views_filter_handler_simple.inc index 4fa4c40..c54ec58 100644 --- a/date_views/includes/date_views_filter_handler_simple.inc +++ b/date_views/includes/date_views_filter_handler_simple.inc @@ -41,6 +41,7 @@ class date_views_filter_handler_simple extends views_handler_filter_date { $options['default_to_date'] = array('default' => ''); $options['year_range'] = array('default' => '-3:+3'); $options['add_delta'] = array('default' => ''); + $options['expose']['contains']['show_element_description'] = array('default' => 0); return $options; } @@ -55,6 +56,22 @@ class date_views_filter_handler_simple extends views_handler_filter_date { return $operators; } + function expose_form(&$form, &$form_state) { + parent::expose_form($form, $form_state); + + // Display element description setting for date popup. + if ($this->options['form_type'] == 'date_popup') { + $form['expose'] += array( + 'show_element_description' => array( + '#type' => 'checkbox', + '#title' => t('Show date elements description'), + '#default_value' => $this->options['expose']['show_element_description'], + '#description' => t('Current date (and time) as placeholder if there is no value set.'), + ), + ); + } + } + /** * Helper function to find a default value. */ @@ -413,6 +430,7 @@ class date_views_filter_handler_simple extends views_handler_filter_date { '#process' => array($type . '_element_process'), '#prefix' => '
', '#suffix' => '
', + '#show_element_description' => $this->options['expose']['show_element_description'], '#states' => array( 'visible' => array( ":input.{$prefix}-choose-input-type" => array('value' => 'date'), @@ -429,6 +447,7 @@ class date_views_filter_handler_simple extends views_handler_filter_date { ":input.{$prefix}-choose-input-type" => array('value' => 'relative'), ), ), + '#show_element_description' => TRUE, ); if ($which == 'all') { $form[$prefix . '_group']['#pre_render'][] = 'ctools_dependent_pre_render';