Let's say you have two separate forms. They each have a managed file element and they have the same name in this case upload. It's the same

$form['upload'] = array(
    '#type' => 'managed_file',
    '#title' => t('Upload a new file'),
    '#description' => theme('file_upload_help', array('description' => '', 'upload_validators' => $validators)),
    '#upload_location' => file_entity_upload_destination_uri($params),
    '#upload_validators' => $validators,
    '#progress_indicator' => 'bar',
    '#required' => TRUE,
  );

If the validators are different then the same validators are used on all forms. This is caused by the js validation just looking for #edit-upload-upload. We need to have it look for the form id so it's #form-id #edit-upload-upload.

I also wonder why #edit-upload-upload isn't really unique. Patch attached shortly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

redndahead’s picture

Status: Active » Needs review
FileSize
639 bytes

Here is the patch.

Devin Carlson’s picture

Status: Needs review » Reviewed & tested by the community

I just ran into this issue while working on #1620096: Upload Media fails after file/add was moved from Media to File Entity. When trying to upload a file, validation would fail and mention that no file was selected.

The patch in #1 applied cleanly and allowed the file to be uploaded successfully. Tested with D8 and D7.

Damien Tournoud’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Hm, sorry what?

I also wonder why #edit-upload-upload isn't really unique.

This is the bug that needs to be fixed. #id is typically generated by drupal_html_id() and guaranteed to be unique (even across AJAX rebuilds of the page). Please investigate why it is not in your case.

redndahead’s picture

Yeah I'm seeing that now that I'm writing a test module for this issue. The problem I have right now is my test module isn't validating at all. I'll continue to look into this.

redndahead’s picture

Title: managed_file field doesn't validate if multiple forms exist with the same field on the same page » managed_file file extension validation issues
Status: Postponed (maintainer needs more info) » Active

So here is a test module that still shows issues with managed_file. Please correct the code if I made a mistake, but while upload does indeed get a unique id with this it doesn't validate on the document upload. It seems to only validate on the image upload.

@Devin Carlson My issue originally stemmed from the media module also so it may be something that needs to get fixed there.

redndahead’s picture

FileSize
903 bytes

And of course I forgot to attach the module.

Once you enable the module go to http://yoursite.com/issue-1620030 and try to upload a document to the image field. It'll through an error. If you then try to upload an image into the document field it'll let you do it.

redndahead’s picture

Version: 8.x-dev » 7.x-dev
FileSize
619 bytes

I can't replicate this in d8 anymore. But it's still happening in d7. Not sure what commit fixed this in d8, but uploading the d7 patch so I can use it in my builds.

redndahead’s picture

Status: Active » Needs review
redndahead’s picture

Issue summary: View changes
FileSize
595 bytes

Re-roll

poker10’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#2594955: [D7] Duplicate HTML IDs are created for file_managed_file fields

Thanks for the patch. I think this issue could be a duplicate of this: #2594955: [D7] Duplicate HTML IDs are created for file_managed_file fields where the patch is RTBC now. Maybe you can try the patch from that issue if it fixes the problem?