@@ -54,6 +54,7 @@ public static function addItem(array &$form, FormStateInterface $formState): voi
5454 $ data = $ formObject ->calculateData ($ formState );
5555 $ formState ->setTemporary ($ data );
5656
57+ $ formState ->clearErrors ();
5758 $ formState ->setRebuild ();
5859 }
5960
@@ -145,6 +146,13 @@ public static function removeItem(array &$form, FormStateInterface $formState):
145146 Assertion::integer ($ pos );
146147 $ indexToRemove = (int ) substr ($ name , $ pos + 1 );
147148
149+ $ input = &NestedArray::getValue ($ formState ->getUserInput (), $ propertyPath );
150+ if (is_array ($ input )) {
151+ // Update input so value callbacks get the correct values.
152+ unset($ input [$ indexToRemove ]);
153+ $ input = array_values ($ input );
154+ }
155+
148156 $ arrayItems = $ formState ->getValue ($ propertyPath );
149157 Assertion::isArray ($ arrayItems );
150158 unset($ arrayItems [$ indexToRemove ]);
@@ -163,6 +171,7 @@ public static function removeItem(array &$form, FormStateInterface $formState):
163171 Assertion::integer ($ numItems );
164172 $ propertyAccessor ->setProperty ('numItems ' , $ numItems - 1 );
165173
174+ $ formState ->clearErrors ();
166175 $ formState ->setRebuild ();
167176 }
168177
0 commit comments