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.
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
Comment #3
hussainwebCommitted the fix.