Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By sam711 on
If a number display field is set with setRequired(TRUE) and is not filled out NumberWidget::errorElement returns NULL which results in drupal_set_message(NULL) and ajax error at the UI.
NumberWidget
public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) { return $element['value']; }
As opposed to WidgetBase:
public function errorElement(array $element, ConstraintViolationInterface $error, array $form, FormStateInterface $form_state) { return $element; }
I think NumberWidget should be something like:
public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) { return is_null($element['value'])?'':$element['value']; }