From: Christian Weiske on
Hi Alexey,


Element IDs have to be specified explicitly in the attributes array,
otherwise they are autogenerated - with an index appended to them:
Element named "username" gets ID "username-0". While this makes sense
for large and complicated forms, it is not really convenient for small
forms with no duplicated element names.

How am I supposed to get "pretty" IDs automatically? Overwriting
generateID() is not really possible, since I would have to do that for
every single element class.

--
Regards/Mit freundlichen Grüßen
Christian Weiske

-=≡ Geeking around in the name of science since 1982 ≡=-
From: Alexey Borzov on
Hi Christian,

On 03.05.2010 23:04, Christian Weiske wrote:
> Element IDs have to be specified explicitly in the attributes array,
> otherwise they are autogenerated - with an index appended to them:
> Element named "username" gets ID "username-0". While this makes sense
> for large and complicated forms, it is not really convenient for small
> forms with no duplicated element names.
>
> How am I supposed to get "pretty" IDs automatically? Overwriting
> generateID() is not really possible, since I would have to do that for
> every single element class.

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.

Anyway, I probably still have an alternative implementation of generateId()
laying around somewhere, it uses element name as default and only appends
indexes if necessary.
From: Christian Weiske on
Hi Alexey,


> Anyway, I probably still have an alternative implementation of
> generateId() laying around somewhere, it uses element name as default
> and only appends indexes if necessary.
That sounds like the best method to me.


--
Regards/Mit freundlichen Grüßen
Christian Weiske

-= Geeking around in the name of science since 1982 =-
From: Bertrand Mansion on

Le 4 mai 2010 à 10:16, Alexey Borzov a écrit :

> Hi Christian,
>
> On 03.05.2010 23:04, Christian Weiske wrote:
>> Element IDs have to be specified explicitly in the attributes array,
>> otherwise they are autogenerated - with an index appended to them:
>> Element named "username" gets ID "username-0". While this makes sense
>> for large and complicated forms, it is not really convenient for small
>> forms with no duplicated element names.
>>
>> How am I supposed to get "pretty" IDs automatically? Overwriting
>> generateID() is not really possible, since I would have to do that for
>> every single element class.
>
> 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')




--
Bertrand Mansion
Work : http://www.mamasam.com

From: Christian Weiske on
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 =-