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(
    '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.

1 Answer 1


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;
  • Thanks for the reply. Right now it apply class to outer div. I want to add class to its individual checkbox.
    – YKJ
    Jul 11, 2014 at 9: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, 2014 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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