0

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!

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

1 Answer 1

1

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:

Drupal.attachBehaviors();
1
  • 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
    Commented Feb 10, 2015 at 21:01

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.