Re: HTML_QuickForm2_Node: ID generation

From: Date: Tue, 04 May 2010 12:29:42 +0000
Subject: Re: HTML_QuickForm2_Node: ID generation
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-30500@lists.php.net to get a copy of this message
Hello Bertrand, > > 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. I see the benefits of that system - for complex forms. > 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? -- Regards/Mit freundlichen Grüßen Christian Weiske -= Geeking around in the name of science since 1982 =-

« previous php.pear.general (#30500) next »