I am creating a form which dynamically changes based on the value of a select element. What happens is this:
- The user selects a value from the select element
- The select element uses Drupal's ajax methods to reload the form, now with some new elements for further configuration
- Some of the new elements need to be turned into jQuery widgets.
Now, the obvious solution here is to use behaviors to run the widget initialization code. The issue is that I don't know ahead of time which elements need to have what code run on them. I will only know that at the time the ajax portion of the form loads.
An alternate solution is to pre-load all of the possible configuration elements and inject all of the behaviors ahead of time. For various reasons this isn't a good idea, not least because I rather like lazy loading.
My question is: is there some way to attach behaviors in php through Drupal's ajax mechanism, like there is a way to modify the settings?