Magento Forum

   
Varien_Data_Form_Element_Radios bogus class behavior
 
Alisson Oldoni
Member
 
Avatar
Total Posts:  45
Joined:  2009-06-26
Balneário Camboriú - SC
 

I’ve reported this as a bug to Varien. I want you guys opinion, I don’t know if this is a known community bug or what.

The Varien_Data_Form is really good, but the Radios renderer behavior just goes against the class-based javascript Validation (that comes with the Prorotype javascript framework).

When you add a class to the radio in the regular way

$form->getElement('main')->addField('genero''radios',
                array(
                    
'label' => Mage::helper('customer')->__('G&ecirc;nero') . ' <span class="required">*</span>',
                    
'class' => 'validate-one-required-by-name',
                    
'name'  => 'order[account][genero]',
                    
'required' => false,
                    
'values' => array(array('label'=>'Masculino''value'=> 'M','class' => 'validate-genero'),array('label'=>'Feminino''value'=>'F')),
                )
            );

...the renderer adds the class name to all the inputs, and the Prototype Validation just get lost adding several error messages (one to each radio button). The fix is to add the class name only to one of the radios of the group, like this:

$form->getElement('main')->addField('genero''radios',
                array(
                    
'label' => Mage::helper('customer')->__('G&ecirc;nero') . ' <span class="required">*</span>',
                    
/* 'class' => 'validate-one-required-by-name', */
                    
'name'  => 'order[account][genero]',
                    
'required' => false,
                    
'values' => array(array('label'=>'Masculino''value'=> 'M','class' => 'validate-genero'),array('label'=>'Feminino''value'=>'F')),
                    
/* double error message bug */
                    
'after_element_html' => '<script type="text/javascript">Event.observe( window, "load", function () { $("generoM").className = "validate-one-required-by-name"; } ); </script>'
                
)
            );

But this is just a workaround, i guess the whole beavior of the radio button should be updated, since it also has another bug in the “required” parameter. When it is set to “true” it will always return a error, since, in a radio button group, there always will be one button that is not selected. It simply ignores the fact that the radio buttons work in a way that they will never be all selected.

Thanks!

Image Attachments
magento_bug.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top