0

I am working with System->user->Add new user->User Role.
I am changing in core file for temporary purpose.
Expected Result:
Want to apply class 'validate-one-required-by-name' to user role radio button.
What I Done:-

magento\app\code\core\Mage\Adminhtml\Block\Permissions\User\Edit\Tab\Roles.php

I have added class to radio button. as below. But it is not reflecting on webpage.

protected function _prepareColumns()
{

    $this->addColumn('assigned_user_role', array(
        'header_css_class' => 'a-center',
        'header'    => Mage::helper('adminhtml')->__('Assigned'),
        'type'      => 'radio',
        'class'     => 'validate-one-required-by-name',
        'html_name' => 'roles[]',
        'values'    => $this->_getSelectedRoles(),
        'align'     => 'center',
        'index'     => 'role_id'
    ));

Current Outout is

input type="radio" class="radio" value="1" name="roles[]"

Required

input type="radio" class="radio validate-one-required-by-name" value="1" name="roles[]"

Thanks in advance.

1

The problem is that when rendering these radio items Magento use the class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Radio.

If you look into this class you will see that there is a function render. This function builds the actual html for this element and here you will see that therre is no way of setting the class against the radio.

$html = '<input type="radio" name="' . $this->getColumn()->getHtmlName() . '" ';
$html .= 'value="' . $row->getId() . '" class="radio"' . $checked . '/>';

One way of achieving what you are looking for is to rewrite the class and change the render function to match your needs. You will need to rewrite the class path adminhtml/widget_grid_column_renderer_radio in your modules config.xml.

If you add the attribute 'your_render_class' when you add the column then in the render function you can use $this->getColumn()->getYourRenderClass(). Be aware that when you rewrite this then it will do it for all radio buttons in grid columns.

| improve this answer | |
0

Have a look in Mage_Adminhtml_Block_Widget_Grid_Column and you can see methods for getCssClass() and getHeaderCssClass(). These methods pull data from column_css_class and header_css_class so this is what you need to be using (instead of just class) to define your column CSS classes in the arguments passed to addColumn().

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.