managed_file alters form_state losing preset values.

Created on 11 July 2014, over 10 years ago
Updated 24 April 2023, over 1 year ago

After uploading a file on a node form values earlier set using a form_alter are lost.
It doesn't seem to matter whether I use #value or #default_value.

Using a hack like altering the $form_state['complete_form'] in a validate doesn't solve the problem because one of the fields is a required field so an error is already set preventing the form from being submitted. (even though the value is set, clicking submit a second time submit's the form)

The fields that are causing the problem are select fields. (one entity reference select list, and a select list (text).
I can't be certain this problem is limited to Drupal 8 Alpha 12 only. (I remember having a similar problem on Drupal 7)

/**
 * Implements hook_form_alter()
 */
function test_form_alter(&$form, &$form_state, $form_id) {

  // check if field available
  if (!empty($form['field_test_field'])) {
    $form['field_test_field']['widget']['#value'] = 1;
  }
}
πŸ› Bug report
Status

Closed: outdated

Version

8.0 ⚰️

Component
FormΒ  β†’

Last updated 2 days ago

Created by

πŸ‡³πŸ‡±Netherlands thomasdik

Live updates comments and jobs are added and updated live.
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.

Production build 0.71.5 2024