I’ve got a page that, in response to a button click, brings up a Bootstrap modal form. In that form is a textfield with the standard Drupal autocomplete behavior; it’s working fine.
I now want to set things up so that, after a value is put into that field, another mostly-identical autocomplete field is added to the form — the idea is to let the user specify additional values for the property being handled by this part of the form.
I’ve hung a jQuery blur handler off the textfield that takes the HTML that ends up in the form for the initial autocomplete form, parameterizes it a bit to avoid duplicate ID numbers, and inserts this updated field into the form when the first field gets a value. This is working fine from an HTML perspective, but the autocomplete behavior is not happening on the added form.
Minor notes:
-
After I insert the new field into the form, I re-run
Drupal.attachBehaviors()
, which I thought was going to make this all work. I’ve also added a delay to make sure the rewriting of the form is completed beforeattachBehaviors()
is called, but that has no effect. -
The autocomplete behavior continues to work on the original field after the new field is added to the form.
-
The blur handler that does all this stuff to the first autocomplete field is not firing when I blur control from the second, added field.
It looks like some other bit of initialization stuff needs to happen, but I have no clue what it is. Does anybody else? Thanks!
Sponsored by SupremePR