Skip to content

radio elements are unchecked when added to a form #11

@sbraz

Description

@sbraz

Hi,
When creating a radio element and adding to it a checked attribute, the attribute is properly displayed.
However, when the element is added to a form, its checked attribute is removed.

There is no such problem with checkbox elements.

This is the line that removes the attribute:

$this->setChecked(false);

And this is the traceback to its call:

#0 /tmp/HTML/QuickForm.php(634):
HTML_QuickForm_radio->onQuickFormEvent('updateValue', NULL,
Object(HTML_QuickForm))
#1 /tmp/test.php(9):
HTML_QuickForm->addElement(Object(HTML_QuickForm_radio))
#2 {main}

The onQuickFormEvent function is slightly different for checkbox elements, maybe it
needs to be changed but I don't really know what a change implies:

The following test code demonstrates the problem:

<?php
require_once "HTML/QuickForm.php";
$elem = HTML_QuickForm::createElement("radio");
$elem->setChecked(true);
$qf = new HTML_QuickForm();
echo "ELEM\n";
$elem->display();
echo "\n\nFORM";
$qf->addElement($elem);
$qf->display();
echo "\n";

Result:

ELEM
<input type="radio" id="qf_163e0a" checked="checked" />

FORM
<form action="test.php" method="post" name="" id="">
<div>
<table border="0">

        <tr>
                <td align="right" valign="top"><b></b></td>
                <td valign="top" align="left">  <input type="radio"
id="qf_163e0a" /></td>
        </tr>
</table>
</div>
</form>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions