1

I'm trying to remove the "size" attribute from Drupal's FileField output. Right now, it outputs a tag like this:

 <input type="file" name="files[image]"  class="form-file" id="edit-image" size="40" />

I tried a number of permutations of using unset() in a #pre_render callback in my custom module, but I just wind up with size="". The attribute itself never goes away, so HTML5 validators continue to complain. Is there another way to accomplish this, or a way to truly ensure that your callback runs last? $form['mystuff'][] = 'mycallback' is not doing the trick, and plain old unset($form['mystuff']['#size']) runs far too late.

apaderno
  • 28,547
  • 16
  • 75
  • 90
J B
  • 390
  • 1
  • 4
  • 16

1 Answers1

1

Have you tried hook_form_alter()?

function YOUR_THEME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'YOUR_FORM_ID') { // Selects the form you want        
    $form['YOUR_FIELD_NAME']['#size'] = NULL;
  } 
}

With this I've been able to remove size and add HTML5 bits like placeholders etc:

$form['name']['#attributes'] = array('placeholder' => t('username'));
SpaceBeers
  • 13,617
  • 6
  • 47
  • 61