Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
forms system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
13 Feb 2006 at 04:00 UTC
Updated:
6 Oct 2013 at 14:04 UTC
Jump to comment: Most recent file
Comments
Comment #1
drumm"ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")." http://www.w3.org/TR/html4/types.html#type-name
I don't think #title will consistently fulfill that at all.
Comment #2
Crell commentedYou know, I'm pretty sure this can be done with form_alter these days, so let's just do that and be done with it.
Comment #3
ultimateboy commentedCrell #2: I actually think that this is an issue.. almost every form-item has an id, except for fieldsets, and this is not very consistent.
drumm #1: I have re-written the patch using form_clean_id so that the string is of the correct format.
Comment #4
robloachShould the
drupal_strtolowercall become part of the form_clean_id() function?Comment #5
ultimateboy commentedI believe it should. Although the w3c does not specifically state so, it has become a standard throughout drupal and the web development community in general. I have attached a patch which still adds ids to fieldsets but also alters the form_clean_id function.
Comment #6
Zarabadoo commentedI agree with UltimateBoy. It looks to be an unsaid standard in Drupal anyway, so this will just give things that extra level of consistency.
Comment #7
robloachI thought we should be nice to both $element['#id'] and $element['#attributes']['id'] if they already exist.
Comment #8
ultimateboy commentedAh yes.. good point. Applies cleanly and gets the job done. This is a simple enough patch, so I am marking as rtbc.
Comment #9
robloachShouldn't it be using the fieldset name instead of the title? Since the title can be translated, it makes the ID kind of useless.
Comment #10
robloachThis adds a #key property to all the form elements, and then uses that to construct the ID of fieldsets. I was having a look at #name and #id, but we can't really use those because they're required special use cases for input elements.
Comment #11
ultimateboy commentedI like this patch, but is there a reason why you removed the
drupal_strtolowercall from form_clean_id()?Comment #12
robloachI removed the call to drupal_strtolower from the previous patch because now it's using the element's actual key rather then the element's title. So, there won't be any capitals being passed through it anyway. The call therefore isn't required.
The form element's key is what it's called when using $form['myelement']....The key for $form['myelement'] is "myelement".
Comment #14
dalad commentedLinking the fieldset id to the title is not recommended IMO. What if the site is multilanguage? A better approach would be using a static variable in the theme_fieldset method that increments itself every time a fieldset is placed. This is what I came out with (tested D6)
Cheers
Comment #15
robloachThe patch I posted does not use the title, it uses the form's key name instead, which is always the same no matter if the site is multilingual. The form_clean_id function that is used in the patch manages that static variable numbering that you're talking about for us.
Comment #16
ultimateboy commentedRe-roll.
Comment #17
moshe weitzman commentedlooks nice to me. bot is happy so rtbc
Comment #18
webchickI wonder if it makes sense to prefix the ID with something. I imagine if you named your fieldset 'messages' or 'content' or something similar we'd end up with duplicate IDs on the page.
I'd also love to get a FAPI guru to ensure the additions to form_builder() are okay.
Comment #19
moshe weitzman commentedform_clean_id() ensures uniqueness and is used in this patch.
Comment #20
chx commentedThat's some mighty convoluted patch. Why are we not setting #id right where this patch hands down key instead? This would give all #input FALSE an #id.
Comment #21
casey commented#680196: Add specific classes to vertical tab li elements
Comment #22
robloachform_process_fieldset injects:
Comment #24
zualas commentedNot sure which patch had a green light, but what I did is put the div id equal to class. To do that, I inserted the following code in lines 1515-1517 in form.inc:
I'm not a programmer so I'm not sure if it's the best way, but it doesn't rely on the #title so there will be no problems with i18n.
Comment #25
dunx commentedA bit of info if you're trying to add an id to a location fieldset. You can't add the id to the locations part of the $form, but instead have to add it to the location array under it. So:
$form['locations'][0]['#attributes']['id'] = t('location');Rather than what I thought was more obvious:
$form['locations']['#attributes']['id'] = t('location');