I have an existing autocomplete field outside of Drupal that uses jQuery UI's autocomplete functionality and makes a call to a custom PHP script to parse the input and return formatted data as JSONP. I need to migrate this field to Drupal.

I've created a custom field module, but I can't figure out how to bind the JS functions if the field allows multiple values. At the moment, I have the IDs of the HTML elements I need to use set with the name-'.$delta.' to append the delta to the ID name. Is there a way to bind JS functionality to a field in Drupal like a custom field behavior call or will I need to create a function in my JS to manipulate the ID and extract the delta that way?

I need one function to run when the field is presented as a widget (node/edit), and a different function to run when the field is presented as a formatter (node/view).

Also, is there a hook to tell Drupal about my JSON service PHP file, or do I just drop it in an includes folder in my module and link to it from my JS file?

1 Answer 1


I ended up solving this by using hook_menu() to create an AJAX tie-in with a custom callback function and then tied the form field to the AJAX path with 'autocomplete path' => '/...' in the field parameters. No need for any custom JS to make it work.

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.