2

I am trying something that have been probably discussed already, but I can't seem to find it. I have a node reference field that I would like to use the "Autocomplete field" function with. However, I would like to show an extra (custom) field, not only the Title of the node. Preferably in a comma separated list, like:

TITLE Node 1, custom field TITLE Node 2, custom field

etc.

I'm sure this can be done. But I can't seem to find how (and yes.. I'm a beginner I'm affraid).

Thanks a million!

2 Answers 2

3

Instead of using Node Reference (References), I suggest you to use Entity Reference module. It has an option to build the autocomplete options with a view so that you can add other fields.

1
  • Clean way,I missed it.
    – arpitr
    Oct 14, 2013 at 6:54
1

Assuming you are using references module for node reference.

You can get better hold of how you can do this looking inside sub-module of references module called "node-references".

you need to check if this idea works for you.

  1. Implement hook_field_widget_form_alter() in your custom module,implementing this hook you can change the callback function which provides autocomplete suggestions.

As in node_refernce.module line number 606 node_reference_field_widget_form() has been implemented so keeping the same workflow you just have to override "value_callback" with your custom function.Lets call you custom as "custom_autocomplete_suggestions()"

  1. Now in your custom function custom_autocomplete_suggestions() copy the code of existing callback function in node_references module.

  2. Clear your caches, check if you getting autocomplete suggestions or not.If so you have overridden it successfully.

  3. Now do tweaks inside your custom_autocomplete_suggestions() to return what you want as suggestions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.