In the node reference field module we needed the ability to alter the widget that cck adds to the form via js in content_add_more_js(). After a lot of messing around no solution was found.
I decided to copy the entire method and make the two necessary modifications.
Manually require cck code:
require_once drupal_get_path('module', 'content') . '/includes/content.node_form.inc';
Forcefully make alterations to the widget element.
$referenceable_fields = variable_get('nodereference_field_' . $field_name . '_fields', array());
nodereference_field_element_alter($form, $field, $referenceable_fields);
Change the code that selects the final element from the form to:
$field_form = (!empty($group_name)) ? $form[$group_name][$field_name . '_container'] : $form[$field_name . '_container'];
It would seem some sort of alter hook is in order.
Comments
Comment #1
markus_petrux commentedThere's already a drupal_alter('form') in the AHAH handler for "Add more items" requests. You can implement your hook_form_alter() like this:
You should be able to figure out whether the request is for a field managed by your widget, and then alter the element to suit your needs.
Comment #2
boombatower commented@markus_petrux: Thanks. I will attempt that and move issue back if it does not work. Interestedly enough I looked right at the line and missed the fact that it was doing that.