Closed (duplicate)
Project:
Content Construction Kit (CCK)
Version:
6.x-2.x-dev
Component:
text.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
22 May 2009 at 16:03 UTC
Updated:
28 Jul 2009 at 23:45 UTC
I'm trying following code in hook_form_alter()
$form[$field_name]['#attributes'] = array('onchange' => "alert('test');");
where $field_name is existing object provided by text module (cck).
But it doesn't work.
In theme_content_multiple_values() there is Drupal recursive call to:
$output .= drupal_render($element[$key]);
Here is $element (so when parsing $element[$key] there is no #attributes):
$element
: array =
#programmed: bool = FALSE
#post: array =
#attributes: array =
onchange: string = "alert('test');"
#parents: array =
0: string = "field_address_city"
#array_parents: array =
0: string = "group_parent_details"
1: &string = "field_address_city"
#defaults_loaded: bool = TRUE
#processed: bool = FALSE
#count: long = 5
#access: bool = TRUE
#description: string = ""
#required: string = "1"
#title: string = "Town/City"
0: array =
#type: string = "text_textfield"
#default_value: array =
value: undefined = NULL
#title: string = "Town/City"
#description: string = ""
#required: bool = TRUE
#weight: long = 0
#delta: &long = 0
#columns: array =
0: string = "value"
#field_name: string = "field_address_city"
#type_name: string = "parent"
#post: &array =
#programmed: &bool = FALSE
#tree: bool = TRUE
#parents: array =
0: string = "field_address_city"
1: long = 0
#array_parents: array =
0: &string = "group_parent_details"
1: &string = "field_address_city"
2: &long = 0
#processed: bool = TRUE
#attributes: array =
#input: bool = TRUE
#process: array =
0: string = "text_textfield_process"
#autocomplete_path: bool = FALSE
#name: string = "field_address_city[0]"
#id: string = "edit-field-address-city-0"
#value: array =
value: &undefined = NULL
value: array =
#type: string = "textfield"
#default_value: undefined = NULL
#autocomplete_path: &bool = FALSE
#size: string = "60"
#attributes: array =
class: string = "text"
#title: &string = "Town/City"
#description: &string = ""
#required: &bool = TRUE
#field_name: &string = "field_address_city"
#type_name: &string = "parent"
#delta: &long = 0
#columns: &array =
#maxlength: undefined = NULL
#post: &array =
#programmed: &bool = FALSE
#tree: &bool = TRUE
#parents: array =
0: string = "field_address_city"
1: &long = 0
2: string = "value"
#array_parents: array =
0: &string = "group_parent_details"
1: &string = "field_address_city"
2: &long = 0
3: &string = "value"
#weight: long = 0
#processed: bool = TRUE
#input: bool = TRUE
#process: array =
0: string = "form_expand_ahah"
1: string = "fckeditor_process_input"
#name: string = "field_address_city[0][value]"
#id: string = "edit-field-address-city-0-value"
#value: string = ""
#defaults_loaded: bool = TRUE
#sorted: bool = TRUE
#printed: bool = TRUE
_error_element: array =
#type: string = "value"
#value: string = "field_address_city][0][value"
#post: &array =
#programmed: &bool = FALSE
#tree: &bool = TRUE
#parents: array =
0: string = "field_address_city"
1: &long = 0
2: string = "_error_element"
#array_parents: array =
0: &string = "group_parent_details"
1: &string = "field_address_city"
2: &long = 0
3: &string = "_error_element"
#weight: double = 0.001
#processed: bool = FALSE
#description: undefined = NULL
#attributes: &array =
#required: bool = FALSE
#input: bool = TRUE
#name: string = "field_address_city[0][_error_element]"
#id: string = "edit-field-address-city-0--error-element"
#defaults_loaded: bool = TRUE
#sorted: bool = TRUE
#title: undefined = NULL
#printed: bool = TRUE
#defaults_loaded: bool = TRUE
#sorted: bool = TRUE
#children: string = "<div class=\"form-item\" id=\"edit-field-address-city-0-value-wrapper\">\n <label for=\"edit-field-address-city-0-value\">Town/City: <span class=\"form-required\" title=\"This field is required.\">*</span></label>\n <input type=\"text\" name=\"field_address_city[0][value]\" id=\"edit-field-address-city-0-value\" size=\"60\" value=\"\" class=\"form-text required text\" />\n</div>\n"
#printed: bool = TRUE
#field_name: &string = "field_address_city"
...
#theme: string = "content_multiple_values"
...
#type: string = "markup"
I've tried as well with $form[$field_name][0]['#attributes']
I've got somewhere else element:
'#type' => 'select',
'#attributes' => array ('onchange' => 'CopyToFck();'),
and it does work.
What I'm doing wrong?
Comments
Comment #1
bjaspan commentedI think this is a D6 CCK question, not a D7 Field API question.
Comment #2
kenorb commentedYes, but it's good to try:)
Probably I know what's going on.
When I set that, it's being overridden by function text_textfield_process()
Because there is hardcoded '#attributes' property?
Is there any right way to add '#attributes' into text field to be properly rendered?
Comment #3
kenorb commented#336355: Unable to add '#attributes' or use '#disabled' = true via hook_form_alter()
Comment #4
jonskulski commentedIf you var_dump $element['#attributes'] you will see that any #attribute you set in a form_alter is not present during the _processing.
So I believe the problem is deeper than just being over written.