managed_file: Validation is performed on upload and remove AJAX call

Created on 30 January 2025, about 1 month ago

Problem/Motivation

In a managed_file element validation is performed during the AJAX calls on upload and remove. The validation result isn't used and it looks like it was intended to be disabled by setting #validate to []:
https://git.drupalcode.org/project/drupal/-/blob/11.1.1/core/modules/fil...
https://git.drupalcode.org/project/drupal/-/blob/11.1.1/core/modules/fil...

However, using an empty array has the same result as not setting #validate at all: Default form validation.

Proposed resolution

Set #validate to a callback function that does nothing.

🐛 Bug report
Status

Active

Version

11.1 🔥

Component

file.module

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @dnt
  • First commit to issue fork.
  • riyas_nr changed the visibility of the branch 3503297-managedfile-validation-is to hidden.

  • riyas_nr changed the visibility of the branch 3503297-managedfile-validation-is to active.

  • Pipeline finished with Failed
    28 days ago
    Total: 93s
    #413561
  • Pipeline finished with Failed
    28 days ago
    Total: 559s
    #413569
  • Since validation is explicitly defined in the getInfo() method through #element_validate => [[$class, 'validateManagedFile']] (source), it is clear that validation is intended for the ManagedFile element. Therefore, there is no need to create an empty validation method to disable it, as validation is required and should not be bypassed.

    I initially raised a MR with a proposed solution to disable validation, but the pipeline failed due to test case failures related to text and the ManagedFile element. This indicates that validation is indeed expected and required for this element. We might need to analyze the test failures to determine if they highlight an actual issue or if the approach needs further refinement.

Production build 0.71.5 2024