Do anyone know how I can add the following to form_alter? Currently I've got two integer cck fields which are populated from sql using the php values command.
One field is for make, and the other is for model. Both makes and models are their own node types. Model has a node reference to make.
What I want to do on the Make drop down (CCK: IN开发者_如何学PythonTEGER : SELECT), is on change, modify the contents of the model field. I've made my own bespoke form up, but it's too wieldy and want to use the basic drupal node edit forms.
Ideally I want to be able to pass this into the mix. '#attributes' => array ('onchange'=> 'populatemodels(this,\'edit-field-model\')')
Does any one know of a way of doing this in the code?
In my form_alter adding the attribute doesn't produce any onchanges in the code:
#field_make (Array, 14 elements)
*
#type (String, 20 characters ) optionwidgets_select
*
#default_value (Array, 1 element)
o
0 (Array, 1 element)
+
value (String, 1 characters ) 8
*
#required (String, 1 characters ) 1
*
#columns (Array, 1 element)
o
0 (String, 5 characters ) value
*
#title (String, 4 characters ) Make
*
#description (String, 0 characters )
*
#delta (Integer) 0
*
#field_name (String, 10 characters ) field_make
*
#type_name (String, 3 characters ) car
*
#tree (Boolean) TRUE
*
#weight (String, 2 characters ) -1
*
#access (Boolean) TRUE
*
#count (Integer) 9
*
#attributes (Array, 1 element)
o
onchange (String, 39 characters ) populatemodels(this,'edit-field-model')
Thanks - Matt
I think I've had a break through.
cck/options_widgets.module optionwidgets_select_process($element, $edit, &$form_state, $form) {
Additionally in my form_alter code, I added
drupal_add_js('sites/all/modules/adaptive/adaptive.js');
Which holds the populatemodels script
I've modded this code so that it passes attributes onto the next step
$element[$field_key] = array(
'#type' => 'select',
'#title' => $element['#title'],
'#description' => $element['#description'],
'#required' => isset($element['#required']) ? $element['#required'] : $field['required'],
'#multiple' => isset($element['#multiple']) ? $element['#multiple'] : $field['multiple'],
'#options' => $options,
'#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
>>> '#attributes' => isset($element['#attributes']) ? $element['#attributes'] : NULL, <<
);
By adding '#attributes' => isset($element['#attributes']) ? $element['#attributes'] : NULL, the onchange now appears in the rendered code.
精彩评论