Re: HTML_QuickForm2_Node: ID generation
| From: | Alexey Borzov | Date: | Thu, 13 May 2010 09:57:05 +0000 |
| Subject: | Re: HTML_QuickForm2_Node: ID generation | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-30532@lists.php.net to get a copy of this message | ||
Hi,
On 04.05.2010 16:29, Christian Weiske wrote:
I've committed a change to ID generation: generateId() method now uses 'id_force_append_index' configuration option to check whether it should always append indexes or do it for duplicate elements only. Thus if you do HTML_Common::setOption('id_force_append_index', false); you get the desired behavior. I don't think we really need a way to completely replace generateId(), especially since that method uses protected class variables.I see the benefits of that system - for complex forms.Autogenerating such IDs was Bertrand's idea (CCing him), I was actually in favor of your approach. There probably were some good reasons, but I can't quite remember them, hopefully Bertrand will be able to shed some light here.It makes the element id more predictable than having "username" and then "username-1". It also simplify javascript code in case you have to deal with element ids. For example, it is more consistent and easier to write : var id = "username-" + i; than : var id; if (i == 0) { id = "username"; } else { id = "username-" + i; } It also makes regex matching on elements id faster and easier, CSS3 will support basic regex selectors IIRC. And it reduces your chances to break your own code since you know what to expect all the time, be there one or many elements. I think you have to get used to it to start to see the benefit, I admit it doesn't look "pretty" at first.We could also propose a way to override Node::generateId(), it's just a static function, it could be replaced by any php callback, ids are stored in a static variable as well : Node::useIdGenerator('generateMyId')That's something that would be really, really cool and helpful. Maybe a form attribute?