If a form is using Ajax (even in other fields), the form breaks if the date field is not set before invoking the Ajax callback. For example, in my form, there is an entity browser and if I attempt to load the modal browser without filling in the date field, nothing happens and there is an error reported in the console.

Internal Server Error
ResponseText: The website encountered an unexpected error. Please try again later.InvalidArgumentException: The date cannot be created from a format. in Drupal\Component\Datetime\DateTimePlus::createFromFormat() (line 248 of core/lib/Drupal/Component/Datetime/DateTimePlus.php). Drupal\taarikh\Element\TaarikhDatetime::validateDatetime(Array, Object, Array)
call_user_func_array(Array, Array) (Line: 282)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
...

The problem is that the element is not making any checks before attempting to construct the DateTimePlus object from the format, and this exception is thrown.

We should add checks before attempting to construct this object.

Comments

hussainweb created an issue. See original summary.

  • hussainweb committed ddb7ac4 on 8.x-1.x
    Issue #3086111 by hussainweb: The element may break forms driven by Ajax...
hussainweb’s picture

Status: Active » Fixed

Committed the fix.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.