I've got a D7 page that constructs a Twitter Bootstrap modal form; it appears in response to a click on a button on the page. I'd like to have in that form a textfield that uses the standard Drupal autocomplete mechanism; the problem is that the textfield isn't getting properly hooked into the autocomplete system. I'm loading the Bootstrap versions of misc/ajax.js and misc/autocomplete.js into the page with drupal_add_js() so that they'll be around if the modal is invoked, but all the attached behaviors in autocomplete.js aren't getting invoked when the modal form is constructed and presented, and so the textfield stays a regular textfield. Or so I think, anyway -- I'm kinda out of my depth here.

I suppose I could roll my own ajax code for the field, but the basic autocomplete behavior is so obviously the right thing that it ought to be used. Any advice out there? Thanks!

  • You can always call Drupal.attachBehaviors(); to get Drupal's js api kickstarted
    – Clive
    Feb 10 '15 at 16:41

Drupal's JS is powered by behaviors. If you find yourself in a situation where you need to poke the system into life, you can manually attach the behaviors like so:

  • This works nicely, as noted above. For future visitors, I also had to add a call like "drupal_add_library('system', 'drupal.autocomplete')" along with the drupal_add_js's.
    – Jim Miller
    Feb 10 '15 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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