@@ -74,7 +74,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
74
74
],
75
75
];
76
76
}
77
- $ form_state ->setCached (FALSE );
78
77
$ form ['actions ' ]['submit ' ] = [
79
78
'#type ' => 'submit ' ,
80
79
'#value ' => $ this ->t ('Submit ' ),
@@ -108,6 +107,9 @@ public function addOne(array &$form, FormStateInterface $form_state) {
108
107
$ name_field = $ form_state ->get ('num_names ' );
109
108
$ add_button = $ name_field + 1 ;
110
109
$ 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().
111
113
$ form_state ->setRebuild ();
112
114
}
113
115
@@ -122,6 +124,9 @@ public function removeCallback(array &$form, FormStateInterface $form_state) {
122
124
$ remove_button = $ name_field - 1 ;
123
125
$ form_state ->set ('num_names ' , $ remove_button );
124
126
}
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().
125
130
$ form_state ->setRebuild ();
126
131
}
127
132
0 commit comments