Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

HTML Select Field Class Question…
 
CreedFeed
Member
 
Total Posts:  74
Joined:  2007-08-31
Milwaukee, WI
 

What I want to do is include the HTML property of tabindex in the html code for a select form field so it should spit out something similar to this:

<select name="country_id" id="country" class="validate-select" title="Country" tabindex="1">

The specific code I’m looking at is the getCountryHtmlSelect function:

public function getCountryHtmlSelect($defValue=null)
    
{
        Varien_Profiler
::start('TEST: '.__METHOD__);
        if (
is_null($defValue)) {
            $defValue 
$this->getCountryId();
        
}
        $cacheKey 
'DIRECTORY_COUNTRY_SELECT_STORE'.Mage::app()->getStore()->getId();
        if (
Mage::app()->useCache('config') && $cache Mage::app()->loadCache($cacheKey)) {
            $options 
unserialize($cache);
        
else {
            $options 
$this->getCountryCollection()->toOptionArray();
            if (
Mage::app()->useCache('config')) {
                Mage
::app()->saveCache(serialize($options), $cacheKey, array('config'));
            
}
        }
        $html 
$this->getLayout()->createBlock('core/html_select')
            ->
setName($name)
            ->
setId($id)
            ->
setTitle(Mage::helper('directory')->__($title))
            ->
setClass('validate-select')
            ->
setValue($defValue)
            ->
setOptions($options)
            ->
getHtml();

        
Varien_Profiler::stop('TEST: '.__METHOD__);
        return 
$html;
    
}

In that code where it assigns the HTML code of the select field to a variable $html, what would I need to do to include other html attributes to be printed out? There is a class that generates select fields located in:

app/core/Mage/Core/Block/Html/Select.php

This class references a function $this->getExtraParams() which would seem like it would process extra params and convert them into HTML attributes, however I cannot find any code to define what getExtraParams does. It appears the function does not exist.

Can anyone help me figure out how I would specify a tabindex attribute to the select tag without modifying the core file app/core/Mage/Core/Block/Html/Select.php ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

Try ->setExtraParams(’tabindex="1"’)

 
Magento Community Magento Community
Magento Community
Magento Community
 
CreedFeed
Member
 
Total Posts:  74
Joined:  2007-08-31
Milwaukee, WI
 

Thank you! One more question, what if I want to set multiple parameters, do I just pass a string as in:

->setExtraParams('tabindex="1" attrib="test" magento="rocks"')

edit >> nm, that’s how it’s done. Thanks again!

 
Magento Community Magento Community
Magento Community
Magento Community
 
nelamurugan
Jr. Member
 
Avatar
Total Posts:  22
Joined:  2009-01-15
Chennai
 

In the same way is there any way to custom attribute to each option filed in the select list.

Eg:

<select name="Namen" size="6">
<option label="Anna” rel="yes”>Anna</option>
<option label="Bernhard” rel="no”>Bernhard</option>
</select>

I have added this in the address select function.

foreach ($this->getCustomer()->getAddresses() as $address) {

$options[] = array(

‘value’=>$address->getId(),
‘rel’=>1,

‘label’=>$address->format(’oneline’)

);

}

But it doesnot reflect.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top