Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.2.16

Bug #8057 setDefaults changes radio button selection
Submitted: 2006-06-28 15:07 UTC
From: m dot verkerk at gmail dot com Assigned: avb
Status: Closed Package: HTML_QuickForm (version 3.2.6)
PHP Version: 5.1.4 OS: Linux / Windows
Roadmaps: (Not assigned)    
Subscription  


 [2006-06-28 15:07 UTC] m dot verkerk at gmail dot com (M. Verkerk)
Description: ------------ When in a form with radio-buttons that are explicitly set 'unchecked' a setDefaults command is given with any other element, the first radio button becomes selected. Workaround: set the 'value' attribute with the element creation statement to the default value. Test script: --------------- <?php require_once 'HTML/QuickForm.php'; $form = new HTML_QuickForm('firstForm'); // Add some elements to the form $r1 = &$form->addElement('radio', 'radio-1', null, "Specify:", 0, null); $form->addElement('text', 'name-1', 'Enter your name:', array('size' => 50, 'maxlength' => 255)); $r2 = &$form->addElement('radio', 'radio-1', null, "My name is John", 1, null); $form->addElement('submit', null, 'Send'); //Explicitly set unchecked $r1->setChecked(false); $r2->setChecked(false); //Set any default value $form->setDefaults(array('name-1'=>' Marijn')); if ($form->validate())exit; $form->display(); ?> Expected result: ---------------- Two unchecked radiobuttons and a textbox with default value " Marijn" Actual result: -------------- First radio button is selected

Comments

 [2006-06-29 14:40 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2006-06-29 19:25 UTC] m dot verkerk at gmail dot com
I have tried to set the default of the radiobutton to 'null'. That didn't make it work either, but it might be easier to have fixed? Thanks for the work-around!
 [2006-06-29 19:50 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2006-07-04 12:51 UTC] m dot verkerk at gmail dot com
Thanks for the explanation!
 [2006-07-12 05:07 UTC] ohm at morishima dot net (Akitoshi MORISHIMA)
Alexey, > OK, a bit of clarification on how this works (or rather doesn't work) > and why it is difficult to fix. How about changing the code you mentioned: if ($value == $this->getValue()) { $this->setChecked(true); } else { $this->setChecked(false); } as if ($value == (string)$this->getValue()) { $this->setChecked(true); } else { $this->setChecked(false); } ?
 [2006-10-07 15:17 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!