I added an address field on a content type and a required integer field. When switching countries the address widget stays the same and I get this error:
Recoverable fatal error: Argument 1 passed to Drupal\Core\Form\FormState::setError() must be of the type array, null given, called in /core/lib/Drupal/Core/Field/WidgetBase.php on line 448 and defined in Drupal\Core\Form\FormState->setError() (line 1157 of /core/lib/Drupal/Core/Form/FormState.php).
I found a temporary workaround for my case and disabled validation until the form is submitted:
public function validateForm(array &$form, FormStateInterface $form_state) {
if($form_state->getTriggeringElement()['#type'] == 'submit') {
parent::validateForm($form, $form_state);
}
}
Comments
Comment #2
subhojit777I tested this with "required" text (plain) field, and it worked without any error. Looks like this is the problem of number widget.
Comment #3
subhojit777Comment #4
amateescu commentedJust tried to reproduce this with latest code for core and the address module and switching countries when a required number widget is also present on the node form works just fine. Can you please test again on a clean Drupal 8 install or provide any other steps that are needed to reproduce the issue?
In any case, the patch is not correct because
\Drupal\Core\Field\Plugin\Field\FieldWidget\NumberWidget::formElement()returns its form array for the 'value' key, soerrorElement()needs to do the same.Comment #5
amateescu commentedActually, it seems this is a duplicate of #2619878: Recoverable fatal error: Argument 1 passed to Drupal\\Core\\Form\\ FormState::setError() must be of the type array, which also happens only with the Address module, so moving back to its queue.
Comment #6
subhojit777git clone --branch 8.0.x http://git.drupal.org/project/drupal.gitgit clone --branch 8.x-1.x http://git.drupal.org/project/composer_manager.gitphp modules/composer_manager/scripts/init.php,composer drupal-update(as per https://github.com/commerceguys/commerce#installation)git clone --branch 8.x-1.x http://git.drupal.org/project/address.gitExpected behavior:
Address fields appear based on the selected country, and no PHP warnings are logged.
Current behavior:
The address fields will not appear, and you will see PHP warnings and error in recent log message.
Now:
Observation:
Address fields appear based on the selected country, and no PHP warnings are logged.
Comment #7
subhojit777More observation:
Observation:
Address fields are added based on the selected country, and no PHP error messages are logged.
This made me think that there is issue with Number field widget.
Comment #8
lukewertz