By iansears on
I use CCK and made a node reference field that I use in a Form.
I need to ADD an attribute to the input object when it renders in a web page.
How is this done?
Here is my example:
<label for="edit-field-org-node-reference-0-node-name">Organization: </label>
<input type="text" maxlength="128" name="field_org_node_reference[0][node_name]" id="edit-field-org-node-reference-0-node-name" size="60" value="" class="form-text form-autocomplete" />
needs to become the same input field but an added "attribute" that runs a javascript function onchange... like this:
<label for="edit-field-org-node-reference-0-node-name">Organization: </label>
<input type="text" maxlength="128" name="field_org_node_reference[0][node_name]" id="edit-field-org-node-reference-0-node-name" size="60" value="" class="form-text form-autocomplete" onChange="lookupinfo(this.value)" />
See that last attribute?
I tried following this but got stuck: http://drupal.org/node/117346
and this: http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...
My attribute works great outside of Drupal in straiht html calling an embedded javascript, but I am having difficulty in how to add this attribute javascript call INTO my existing CCK custom node reference field. Any ideas anyone?
Thanks in advance for thinking about this. :-)
Comments
Possible answer
I may have found THE thread to answer this, though I haven't proven to myself yet.
http://drupal.org/node/280408
Hope this helps anyone looking for answers on this.
Ian
Please
No answers at all? Please, if you have any ideas or even rough pointers for me please comment.
#attributes overwritten
I have been working on a similar problem. I have found something that might help you. See http://drupal.org/node/161666#comment-272621.
I think you could put something like in your hook_form_alter():
I want my javascript applied to several elements so I want to add a class to the relevent elements that will be found by jquery. Unfortunately it appears that CCK is overwriting my #attributes property.
I think I found the answer
I think the answer is here http://drupal.org/node/336355.
The code in this comment (http://drupal.org/node/336355#comment-1150284) worked for me.
Thanks
Thanks