According to #2367229: html5 placeholder in date input field for view exposed filter and this it should looks like this:

/**
 * Implements hook_date_popup_process_alter().
 */
function MODULENAME_date_popup_process_alter(&$element, &$form_state, $context) {
  if ($form_state['complete form']['#form_id'] == 'ad_node_form') {
    if ($element['#id'] == 'edit-field-born-date-ad-und-0-value-datepicker-popup-0') {
      $element['date']['#attributes']['placeholder'][] = t('MM/DD/YYYY');
    }
  }
}

but it doesn't work. This is HTML code around my date field:

<div class="form-field-type-datetime form-field-name-field-born-date-ad field-widget-date-popup form-wrapper" id="edit-field-born-date-ad">            
      <div id="field-born-date-ad-add-more-wrapper">                
        <div class="form-item form-type-date-combo form-item-field-born-date-ad-und-0">                      
          <div class="date-form-element-content">                        
            <div  class="date-no-float container-inline-date">                            
              <div class="form-item form-type-date-popup form-item-field-born-date-ad-und-0-value">                                  
                <div id="edit-field-born-date-ad-und-0-value"  class="date-padding">                                    
                  <div class="form-item form-type-textfield form-item-field-born-date-ad-und-0-value-date">                                           
                    <label for="edit-field-born-date-ad-und-0-value-datepicker-popup-0">Date of birth</label>                                          
                    <input class="date-clear form-text" type="text" id="edit-field-born-date-ad-und-0-value-datepicker-popup-0" name="field_born_date_ad[und][0][value][date]" value="" size="20" maxlength="30" />                                        
                    <div class="description"> MM/DD/YYYY (e.g.<em>09/18/2015</em>)</div>                                    
                  </div>                                
                </div>                            
              </div>                        
            </div>          
          </div>        
        </div>      
      </div>
    </div>
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jasom created an issue. See original summary.

Vinay15’s picture

Try using field name instead of id. This is something which I tried and succeeded :)

/**
 * Implements hook_date_popup_process_alter().
 */
function MODULENAME_date_popup_process_alter(&$element, &$form_state, $context) {
 
  $date_field_names = array(
    // Machine names of fields...
  );

  // Add placeholder.
  if (in_array($element['#field']['field_name'], $date_field_names)) {
    $element['date']['#attributes']['placeholder'] = t('DD/MM/YYYY');
  }

}
Vinay15’s picture

Status: Active » Needs review
jasom’s picture

I did it using this code:

/**
 * Custom function for title alter on 'node_add_form' and 'node_edit_form'
 */ 
function MYMODULE_after_build($form, &$form_state) {
  if (isset($form['#node_edit_form'])) {
    if (!isset($form['#node']->nid) && isset($form['#node'])) {
      switch ($form['#node']->type) {
        case 'ContentTypeName1':
          $form['field_MACHINE_NAME']['und'][0]['value']['date']['#attributes']['placeholder'] = t('MM/DD/YYYY');
          break;

        case 'ContentTypeName1':
          $form['field_MACHINE_NAME']['und'][0]['value']['date']['#attributes']['placeholder'] = t('MM/DD/YYYY');
          break;

      }
    }
  }
  return $form;
}
anpolimus’s picture

Status: Needs review » Needs work

Task without patch has wrong status.

harsha012’s picture

harsha012’s picture

Status: Needs work » Needs review
harsha012’s picture

Status: Needs review » Needs work
harsha012’s picture

harsha012’s picture

Status: Needs work » Needs review
harsha012’s picture

harsha012’s picture

Component: Date Popup » Code
Issue tags: -placeholder +missing placeholder, +#drupalconasia2016, +drupalconasia2016
sumanthkumarc’s picture

@harsha012 Can you help me how to test this issue/patch?

harsha012’s picture

git apply --index

harsha012’s picture

Assigned: Unassigned » harsha012
sumanthkumarc’s picture

@harsha012 steps to reproduce the issue

NWOM’s picture

#9 worked great for me. Thank you!

@sumanthkumarc:

  • Create a Date field with the Date Popup Widget.
  • Make sure the date does not have a default value
  • Apply the patch
  • Clear Cache
DamienMcKenna’s picture

Assigned: harsha012 » Unassigned

Reminder: the "assigned" field is for indicating that you are actively working on something, it is not for indicating that you reported a problem or that you previously worked on a problem and would like attribution. Thanks.

DamienMcKenna’s picture

Version: 7.x-2.9 » 7.x-2.x-dev
Component: Code » User interface
Issue tags: -missing placeholder
FileSize
1.77 KB

Rerolled.

Not sure if this should be added, though.

JParkinson1991’s picture

Updated patch allowing generic placeholders.

Simply checks existence of placeholder attribute definition on parent element and applies to the sub 'date' element where found.

DamienMcKenna’s picture

Status: Needs review » Fixed
Parent issue: » #3241397: Plan for Date 7.x-2.13

This seems simple and straight forward, thank you.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.