0

In module I have Form.php . I have added Checkbox code which is as follows.

$fieldset->addField('title', 'checkboxes', array(
    'label'     => Mage::helper('custommodule')->__('Title'),
    'class'   => 'validate-one-required-by-name',
    'required'  => true,
    'name'      => 'title[]',
    'values' => array(
        array('value'=>'aaa','label'=>'Checkbox1'),
        array('value'=>'bbb','label'=>'Checkbox2'),
        array('value'=>'ccc','label'=>'Checkbox3'),
    ),
    'onclick' => "",
    'onchange' => "",
    'disabled' => false,
    'tabindex' => 1
));

I have added class field in it. 'class' => 'validate-one-required-by-name', but it doesnt applied to output. If you have any other way to apply class to checkbox through JQuery. Please let me know.

YKJ
  • 387
  • 7
  • 16

1 Answers1

0

It is impossible to add a class to the element except if you change the following file (not update safe).

Copy the file from \lib\Varien\Data\Form\Element\Checkboxes.php to app\code\local\Varien\Data\Form\Element\Checkboxes.php

and replace the getElementHtml() with the follwing.

    /**
 * Retrieve HTML
 *
 * @return string
 */
public function getElementHtml()
{
    $values = $this->_prepareValues();

    if (!$values) {
        return '';
    }

    $html  = '<ul class="checkboxes '.$this->_data['class'].'">';
    foreach ($values as $value) {
        $html.= $this->_optionToHtml($value);
    }
    $html .= '</ul>'
        . $this->getAfterElementHtml();

    return $html;
}
anvanza
  • 172
  • 4
  • Thanks for the reply. Right now it apply class to outer div. I want to add class to its individual checkbox. – YKJ Jul 11 '14 at 09:57
  • Thanks i changed same thing in _optionToHtml($option) method. And it works fine for me. Still i have a problem that it return no. of errors as much no. of checkbox available. I want single error for all checkboxes. – YKJ Jul 11 '14 at 10:06