I have a multi-value field type in a content type. During hook_form_alter(), I add an
#ajax property to the field.
Upon execution, the
ajax callback loads a node's custom view mode and two form inputs from another content type into the div.
I am using field_default_form() to generate the form elements.
In order for these addons to persist through clicking the 'Add more' button, I use hook_form_alter() to call the same function that is called by the ajax callback, and I add them into the results/wrapper div.
My problem is that the form elements of the #ajax callback results are not rendered correctly. For example, they do not have a name or id for the <input> tag. One of the fields is an autocomplete field and autocomplete functionality does not get applied to the element.
However, the results of the 'add more' button, which calls
hook_form_alter(), DOES render these elements correctly.
As far as I can tell, the render arrays are identical during generation. It seems to me like some additional processing happens after
hook_form_alter() that does not happen after my #ajax callback.
I have tried adding #theme, #theme_wrapper, #after_build and #rebuild = TRUE keys to the resulting render array elements, but it does not appear to have any effect.
How can I get these elements to render correctly?