phpdatequickform

How to set IDs for select elements of Quickform_date?


Is there some way to add ID attribute to every select element generated by Quickform_date so it would look for example like this?

<select id="date-d" name="date[d]">
    <option value="1">01</option>
    <option value="2">02</option>   
    ...  
    <option value="31">31</option>
</select><select id="date-M" name="date[M]">
    <option value="1">Jan</option>
    ...
    <option value="12" selected="selected">Dec</option>
</select><select id="date-Y" name="date[Y]">
    <option value="2001">2001</option>
    ...
    <option value="2011">2011</option>    
</select>

I need those IDs for changing selected options by JavaScript. Any alternative ideas how to achieve that?


Solution

  • HTML_QuickForm_group::getElements() method turn out to be the key, in case anyone's interested :-)

        $elements['date'] = $form->addElement('date', 'date','Datum:', 
                            array('language'  => 'cs', 
                                  'minYear' => 2005,
                                  'maxYear' => date('Y') + 2));             
        foreach ($elements['date']->getElements() as $key => $element) {
            $element->updateAttributes(array('id'=>'dateSelect'.$key));
        }