Date list value callback breaks AJAX. #access = FALSE.

Created on 14 July 2017, almost 8 years ago
Updated 1 May 2025, about 1 month ago

The situation is the following: I have a form (entity form) and I am setting #access FALSE on a date field (select widget) depending on an other field. I am also updating it via AJAX, so when the field changes ajax callback is triggered, the form rebuilds, the field #access is set to TRUE and from the ajax callback the altered form returned (containing this date field).

This is tough not happening on website, AJAX callback breaks and brings no form. Because in (line 65) the input is NULL, the DrupalDateTime object tries to instantiate from NULL, throws a TypeError (PHP 7 specific error), which is not catched by the try/catch.

Even on a PHP 5 environment it will throw, the only difference that it will be catched, but still display an invalid error on the date field. Limit validation errors don't seem to work at this stage.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
FormΒ  β†’

Last updated 1 day ago

Created by

πŸ‡·πŸ‡΄Romania _Archy_

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • πŸ‡·πŸ‡΄Romania bbu23

    I have encountered a similar issue, but non-related to AJAX.

    My problem seems to happen in validateDatelist and not valueCallback whenever a datelist field that does not have a default value has its access set to FALSE.

    IRL Example:
    - Have a user entity that has a field_birthdate that uses date list
    - The field_birthdate is required, and the user that I am testing with does not have a value set yet for that field
    - Using the simple_pass_reset module, I intend to reset the user's password
    - The simple user pass reset form is after all a User entity form where all fields except for the password fields have the #access set to FALSE.
    - When attempting to change the password for this user, the form throws a validation error for the datelist field (birthdate) saying it's required even though the field is not visible.
    - This does not happen for users that have the field_birthdate already set (default value present)

    As a quick fix, I've added an extra check to the $input_exists to also check if the field exists but it's not accessible. The existance of the input is verified by form state values which are present, so I don't know at the moment if the root cause is somewhere else or not.

Production build 0.71.5 2024