I am trying to add an attribute via the FAPI to image_upload_element and am unable to. Is this implemented? I want to add a class to the input

[code]
$form['photo_upload'] = array(
'#type' => 'image_upload_element',
'#title' => t('Upload your photos'),
'#file_validators' => array(
'file_validate_size' => array(16384),
'file_validate_extensions' => array('gif jpg jpeg png'),
),
'#attributes' => array('class'=>'boxed'),
'#image_preview_size' => '150x150'
);
break;
[/code]

thanks

Comments

alan d.’s picture

Component: Miscellaneous » Code
Status: Active » Postponed (maintainer needs more info)

There are multiple elements nested in the rendered element, so I made a deliberate decision to not to parse any passed in attributes.

The element does have a unique id (as long as all your form elements have unique names), #edit-file-[element name], and the jquery selector "div.upload-element-detail input.form-file" will select these form file input fields.

Guessing that I need to know what you are trying to implement to see if I can help.

I can not remember if I have tried this, but you may be able to implement this yourself by overriding #process with your own function

Eg:

add your process callback: '#process' => array('my_custom_upload_element_expand'),

Add implement something like this:

<?php

/**
 * Our #process callback to expand the control.
 */
function my_custom_upload_element_expand($element, $edit, $form_state, $complete_form) {
  $element = _upload_element_expand($element, $edit, $form_state, $complete_form);
  $element[$element['#name'] .'_upload_element_file']['#class'] = "hello-world";
  return $element;
}
?>

Again, no test environment to try this on at the moment.

Anonymous’s picture

thanks

Anonymous’s picture

What I am trying to do is implement the jquery multifile upload plugin from http://www.fyneworks.com/jquery/multiple-file-upload/#tab-Examples which requires the class be set to "multi" such that the input tag has to look like

The code above is appears to change the class when I do a print_r, but when I view source it doesn't seem to be therem. hmmm.
Thanks for the start though.

alan d.’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Hi bouton

I'm hoping you got to the bottom of this. I guessing that the jquery plugin was updating the classes? Anyway, closing to clean up the issue queue a bit. Open again if it wasn't working.

Regards