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.

Issue fork drupal-3503297

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dnt created an issue. See original summary.

quietone’s picture

Version: 11.1.x-dev » 11.x-dev

riyas_nr made their first commit to this issue’s 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.

riyas_nr’s picture

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.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.