Re: Accessing QF_date elements from javascript (2nd and last try :)
| From: | Cesare D'Amico | Date: | Sat, 22 May 2004 08:46:36 +0000 |
| Subject: | Re: Accessing QF_date elements from javascript (2nd and last try :) | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-12678@lists.php.net to get a copy of this message | ||
Alle 12:16, venerdì 21 maggio 2004, Stanislav Okhvat ha scritto:
> Hi, Cesare,
Ciao :)
> I wanted to note that document.getElementById is unreliable in some
> browsers (Opera) since it requires the element to have an "id"
> attribute and cannot find it by "name" alone.
I think that this is the correct behaviour: the DOM Level 1 defines
these 2 different methods for the interface HTMLDocument (among
others):
getElementById
Returns the Element whose id is given by elementId. If no such
element exists, returns null. Behavior is not defined if more than one
element has this id.
Parameters
elementId
The unique id value for an element.
Return Value
The matching element.
This method raises no exceptions.
getElementsByName
Returns the (possibly empty) collection of elements whose name value
is given by elementName.
Parameters
elementName
The name attribute value for an element.
Return Value
The matching elements.
This method raises no exceptions.
http://www.w3.org/TR/REC-DOM-Level-1/level-one-html.html
Moreover, "name" and "id" semantics are different, so Opera's behaviour
looks correct.
> In IE it tries to find
> the element by name, and then id.
That is, as in most of the cases, a misinterpretation of IE developers
(shall we call it a feature? :)
> I'd suggest that QF developers use
> curly braces when building element 'id', to get something like:
> data_da{d}, data_da{F}, data_da{Y}
I think that the idea suggested by Daniel Kopp is more php-style:
data_da_d, data_da_y, etc. (similar to imagemaps var_x, var_y).
> Also, in view of this Opera's getElementById deficiency, I would also
> generate ids for all elements anyway (even if one is not specified).
> There might be a few catches here, so this should be discussed among
> QF developers.
This is the same idea expressed by Daniel. I poked around the code a bit
(as said, I don't know much about QF internals). It *seems* to me that
this line is a good candidate for such a task:
$this->_elements[] =& new HTML_QuickForm_select($sign, null, $options,
$this->getAttributes());
Line ~ 302 in date.php
Could it be changed to something like:
$this->_elements[] =& new HTML_QuickForm_select($sign, null, $options,
array('id' => 'whatever') + $this->getAttributes());
In this way an "id" eventually passed to the elements of the 'date'
widget (I don't know if one can do that) would overwrite the id
constructed automatically.
I haven't still understood how to build that "whatever", though :)
('name_of_the_date_widget' . 'letter_in_date_format')
How about the idea? Could it be done in a better way?
Thanks, ciao
ce
PS: I would like to say my appreciation for QF code, there are really
nice things like this:
array_walk($options, create_function('&$v,$k','$v = substr($v,-2);'));
QF is really really a *great* work :)
--
Cesare D'Amico - boss (@t) cesaredamico (dot) com
http://cesaredamico.com ~ http://phpday.it ~ http://verona.linux.it/
Key on pgp.mit.edu, ID 92802693.
Questa è la mia vita, se ho bisogno te lo dico, sono io che guido, io
che vado fuori strada, sempre io che pago... non è mai successo che
pagassero per me... [Questa è la mia vita - Ligabue]