@@ -74,7 +74,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
7474 ],
7575 ];
7676 }
77- $ form_state ->setCached (FALSE );
7877 $ form ['actions ' ]['submit ' ] = [
7978 '#type ' => 'submit ' ,
8079 '#value ' => $ this ->t ('Submit ' ),
@@ -108,6 +107,9 @@ public function addOne(array &$form, FormStateInterface $form_state) {
108107 $ name_field = $ form_state ->get ('num_names ' );
109108 $ add_button = $ name_field + 1 ;
110109 $ form_state ->set ('num_names ' , $ add_button );
110+ // Since our buildForm() method relies on the value of 'num_names' to
111+ // generate 'name' form elements, we have to tell the form to rebuild. If we
112+ // don't do this, the form builder will not call buildForm().
111113 $ form_state ->setRebuild ();
112114 }
113115
@@ -122,6 +124,9 @@ public function removeCallback(array &$form, FormStateInterface $form_state) {
122124 $ remove_button = $ name_field - 1 ;
123125 $ form_state ->set ('num_names ' , $ remove_button );
124126 }
127+ // Since our buildForm() method relies on the value of 'num_names' to
128+ // generate 'name' form elements, we have to tell the form to rebuild. If we
129+ // don't do this, the form builder will not call buildForm().
125130 $ form_state ->setRebuild ();
126131 }
127132
0 commit comments