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.

CommentFileSizeAuthor
#11 views-submit-id.patch468 bytesJirkaRybka
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

Note: form IDs are automatically assigned by FAPI.

netbear’s picture

Yes, 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".

merlinofchaos’s picture

Yes, IDs of all form widgets are included as form IDs.

mp’s picture

hi merlinofchaos

is this fixed in the last version?

greets

Dane Powell’s picture

I'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.

Dane Powell’s picture

I 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.

JirkaRybka’s picture

That 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.

Dane Powell’s picture

I 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?

merlinofchaos’s picture

Yes, if javascript thinks the ID will be edit-submit and Drupal changes it to edit-submit-1 that breaks stuff.

Dane Powell’s picture

Okay, in that case I agree that something along the lines of #2 sounds best. It seems like that should be a pretty foolproof solution.

JirkaRybka’s picture

Status: Active » Needs review
FileSize
468 bytes

So, 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.

Dane Powell’s picture

The patch solves the problem on my site. My only two concerns are

  1. I don't know how it might impact other things, such as JS as mentioned in #9
  2. Should the view name be made all lower-case?

If anyone else can answer those questions I think this patch looks good.

JirkaRybka’s picture

1. 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.

Dane Powell’s picture

Status: Needs review » Reviewed & tested by the community
merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 2.x and 3.x branches.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.