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.
When I use more than one exposed filters block on the page there are some buttons with the same id "edit-submit" - validator.w3.org shows errors on page. May be better to use class if possible.
Comment | File | Size | Author |
---|---|---|---|
#11 | views-submit-id.patch | 468 bytes | JirkaRybka |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedNote: form IDs are automatically assigned by FAPI.
Comment #2
netbear CreditAttribution: netbear commentedYes, I know about form id.
I'm talking about button id, not the id of the form. The button has id "edit-submit" for every exposed form on my page. It would be better if it had id "edit-submit-MY_VIEW_NAME" and class "edit-submit".
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedYes, IDs of all form widgets are included as form IDs.
Comment #4
mp CreditAttribution: mp commentedhi merlinofchaos
is this fixed in the last version?
greets
Comment #5
Dane Powell CreditAttribution: Dane Powell commentedI'm still seeing this in 6.x-2.5. In fact you don't even need more than one filter on the page - just having a single filter conflicts with other Drupal elements such as the site search submit button.
Comment #6
Dane Powell CreditAttribution: Dane Powell commentedI know what is causing the error - form_clean_id is being used to generate the button ids (as alluded to in #1), but the form id cache is being flushed in includes\form.inc on line 182 -
form_clean_id(NULL, TRUE);
. When I comment that line out, everything works fine. Supposedly that's there to prevent the id count from "needlessly incrementing." Personally I don't see why that's a problem, compared to completely defeating the purpose of using form_clean_id and producing invalid output.Comment #7
JirkaRybka CreditAttribution: JirkaRybka commentedThat flush was added to fix another issue, where the same forms are built twice on the same page (on previews, I seem to remember - correct me if I'm wrong), making all the IDs (even unique ones) out-of-sync. They said it was a problem for JavaScript or the like. Certainly, the auto-generated ID's stuff is not really foolproof, yet.
Previously, I was just passing unique ID into the '#id' property of the button on my site (#2 have a good idea about 'edit-submit-MY_VIEW_NAME'), but the 6.x FAPI reference seems to mark '#id' as only INTERNAL, so I'm unsure whether it's going to work on 6.x or not. If it works, providing own unique ID might be a good idea.
Comment #8
Dane Powell CreditAttribution: Dane Powell commentedI think I understand why the flush was added, I just don't understand how it's a problem. Was incrementing the IDs actually breaking something, or was it just not ideal?
Comment #9
merlinofchaos CreditAttribution: merlinofchaos commentedYes, if javascript thinks the ID will be edit-submit and Drupal changes it to edit-submit-1 that breaks stuff.
Comment #10
Dane Powell CreditAttribution: Dane Powell commentedOkay, in that case I agree that something along the lines of #2 sounds best. It seems like that should be a pretty foolproof solution.
Comment #11
JirkaRybka CreditAttribution: JirkaRybka commentedSo, patch per #2: Changes the exposed filters submit button ID from duplicates of 'edit-submit' to 'edit-submit-VIEW-NAME'.
(There's already a class 'form-submit', in case someone needs such a thing.) And BTW, I have the problem on my (not finished yet) site too - ID is duplicate to the search box submit.
Comment #12
Dane Powell CreditAttribution: Dane Powell commentedThe patch solves the problem on my site. My only two concerns are
If anyone else can answer those questions I think this patch looks good.
Comment #13
JirkaRybka CreditAttribution: JirkaRybka commented1. It shouldn't affect anything, as we're only just defining own ID on this single button - or is there some JavaScript attached to this very button already? (It would be beroken already, as the same ID appears elsewhere on the page too.) Certainly it won't cause the mentioned issues, where JavaScript was broken due to unexpected/dynamic change to all ID's on a page - we don't affect anything beyond the single button.
2. I guess that just relying on form_clean_id() should be sufficient. I'm not aware of any problems with ID's having uppercase characters.
Comment #14
Dane Powell CreditAttribution: Dane Powell commentedComment #15
merlinofchaos CreditAttribution: merlinofchaos commentedCommitted to 2.x and 3.x branches.