Form loaded programmatically, date blanked out on save

Created on 12 June 2018, over 6 years ago
Updated 5 November 2023, about 1 year ago

We have a form being loaded on a node display page. The form is initially hidden and toggled into view to "Manage files". Since, in this case, we are only interested in showing the "Files" field, all other fields on the form are hidden, and the required setting of all fields is set to FALSE.

That works well for all fields except date fields. When we toggle the file manager into view, and even without changing any of the data there, we just save, we get a validation error message saying the date field is required. That node starts out with a valid date, so it shouldn't be getting the validation error.

The same feature (same code) is running on a content type that has the same date field, but it isn't required for that content type. In that case, on save we don't get the validation error, but the date is blank after the save. Something is blanking the value of the date field when the form is loaded and/or saved.

This is the code that loads the form. It is then passed to a twig template.

  // Get the edit form.
  $formObj = \Drupal::service('entity.manager')
    ->getFormObject('node', 'edit')
    ->setEntity($entity);

  $form = \Drupal::formBuilder()->getForm($formObj);

$entity is the result of Node::load().

πŸ› Bug report
Status

Closed: outdated

Version

11.0 πŸ”₯

Component
DatetimeΒ  β†’

Last updated 6 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States ExTexan

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.

  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    Since this is a stale issue, it would be good to get some steps to reproduce here with a fresh Drupal 10 installation. This would let us verify it's an issue in Drupal itself and not in custom code.

  • Status changed to Closed: cannot reproduce about 1 year ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    @ExTexan, Thank you for reporting this problem. We rely on issue reports like this one to resolve bugs and improve Drupal core.

    There has been no activity here for N years M months.

    More information about this issue was asked for in 10 months ago. No additional information has been supplied, therefor closing.

    If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue β†’ (starting from "Install Drupal core").

    Thanks!

  • Status changed to Closed: outdated about 1 year ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone
Production build 0.71.5 2024