Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#9 | 1620030-d7-3.patch | 595 bytes | redndahead |
#6 | issue_1620030.tar_.gz | 903 bytes | redndahead |
#1 | 1620030-d8-1.patch | 639 bytes | redndahead |
Comments
Comment #1
redndahead CreditAttribution: redndahead commentedHere is the patch.
Comment #2
Devin Carlson CreditAttribution: Devin Carlson commentedI 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.
Comment #3
Damien Tournoud CreditAttribution: Damien Tournoud commentedHm, sorry what?
This is the bug that needs to be fixed.
#id
is typically generated bydrupal_html_id()
and guaranteed to be unique (even across AJAX rebuilds of the page). Please investigate why it is not in your case.Comment #4
redndahead CreditAttribution: redndahead commentedYeah 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.
Comment #5
redndahead CreditAttribution: redndahead commentedSo 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.
Comment #6
redndahead CreditAttribution: redndahead commentedAnd 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.
Comment #7
redndahead CreditAttribution: redndahead commentedI 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.
Comment #8
redndahead CreditAttribution: redndahead commentedComment #9
redndahead CreditAttribution: redndahead commentedRe-roll
Comment #10
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedThanks 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?