I'm using the replace command to replace the fields that were present in the container, with a set of new fields. However any of the data in the new fields aren't sent through form_state. Fields that existed already like $form['columnNum'] are sent through $form_state just fine.

Is there a way to see values of ajax created form elements in $form_state? Or is there a better way to do this entirely?

NOTE: This is all being performed in a blockForm if that makes any difference.

UPDATE:

I changed the field generator to be based on a form_state variable like so

But the form never rebuilds with the new amount of specified fields. I receive the progress animation on change, so I know something is firing. I just get no results. To see if the form was attempting a rebuild I added

1 Answer
1

Move all form building activities from the callback to the form build function.

The form elements you add in the callback go directly through javascript to the DOM in your browser. You see them as normal form elements, but the form API doesn't know that they are in your browser and will ignore them.

Edit for the questions in comments:

In the form build function you know that you are rebuilding because $form_state is filled with data. On the first run it is empty.

You have the number of columns in the value of the select element.

You should wait with handling of the configuration data until submit.

In general an ajax form should have the same code in form build as a normal form, because if jquery is not available, ajax will fallback to a normal rebuild.

I've tried that route but when I change the callback to just increase $this->configuration['columnNum'] and $form->setRebuild(true) and then return $form nothing happens.
– MattAug 11 '16 at 21:55

I don't think that this belongs in the callback either.
– 4k4Aug 11 '16 at 22:08

2

By storing e.g. the element count in $form_state. You increase it there, then rebuild, then based on that build it. ajax must not contain any logic, just return what has been built already.
– BerdirAug 11 '16 at 22:26