I'm building a CTools Panels Content Type (i.e., that thing you insert into panels when adding content, not a type of node) and I am trying to use a form item's #ajax
attribute to set some default values. See code below.
This is all inside of the content type's my_module_content_type_edit_form($form, &$form_state)
call, by the way.
$form['link_type'] = array(
'#type' => 'radios',
'#title' => t('Link Type'),
'#ajax' => array(
'callback' => 'my_module_set_target'
),
'#default_value' => empty($conf['link_type']) ? '_blank' : $conf['link_type'],
'#options' => array('none'=>t('No Link'), 'internal'=>t('Internal Link'), 'external'=>t('External Link'), 'document'=>t('Document Link')),
);
My callback is the following.
function my_module_set_target($form, $form_state) {
watchdog("Test", "Testing callback", array(), WATCHDOG_ALERT);
$form['link_target']['#default_value'] = '_parent';
return $form['link_target']['#default_value'];
}
Regardless of whether the return I'm suggesting would actually work, watchdog()
doesn't even work.
I know CTools does some weird stuff with AJAX, but it can't be that weird. Do you have any idea on how I'd do what I'm wanting to do?
Thanks!
Alternatively: How do I set a default value based on the value of a previous form option?
I figured out how to do this, but it's a bit hacky -- you create new form fields for each dependency fork. You can then merge the values together in hook_content_type_edit_form_submit()
, using whichever one corresponds to the value chosen for the component that initially forked everything.
I'm leaving the question open because I (and, frankly, every programmer I'm working with) is really wanting a good way to use AJAX inside these Panel content type edit forms.
Update: It appears you can't do stuff with #attached, either.
$form['link'][$i] = array(
'#type' => 'fieldset',
'#title' => t('Link #@num', array('@num' => $i)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#attached' => array(
'js' => array(
'alert("Yay.");', 'inline'
),
)
);
ctools_add_js();
ordrupal_add_js();
at the end ofhook_content_type_edit_form();
. If you're just doing simple UI-related stuff, seems like that might be the best call (At least until somebody properly answers this question).