Home » Database » DB_DataObject_FormBuilder » Bug #7919
Different Empty Label for radio buttons
Details
| Request #7919 | Different Empty Label for radio buttons |
|---|---|
| Submitted | 2006-06-16 09:17 UTC |
| From | list dot dhooge at gmail dot com |
| Assigned | justinpatrin |
| Status | Closed |
| Package | DB_DataObject_FormBuilder |
| PHP Version | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2006-06-16 09:17 UTC] list dot dhooge at gmail dot com
Description:
------------
The default blank label used in select isn't good for radio buttons. The following patch creates a new option: radioAddEmptyLabel
Test script:
---------------
Index: FormBuilder.php
===================================================================
RCS file: /repository/pear/DB_DataObject_FormBuilder/FormBuilder.php,v
retrieving revision 1.228
diff -u -U 2 -r1.228 FormBuilder.php
--- FormBuilder.php 7 Jun 2006 15:38:58 -0000 1.228
+++ FormBuilder.php 16 Jun 2006 08:17:56 -0000
@@ -478,9 +478,14 @@
/**
- * An string to put in the "empty option" added to select fields
+ * A string to put in the "empty option" added to select fields
*/
var $selectAddEmptyLabel = '';
/**
+ * A string to put in the "empty option" added to radio fields
+ */
+ var $radioAddEmptyLabel = '--None--';
+
+ /**
* By default, hidden fields are generated for the primary key of a
* DataObject. This behaviour can be deactivated by setting this option to
@@ -1464,4 +1469,6 @@
$formValues[$key] = $this->_do->$key;
if (!isset($element)) {
+ $isRadio = isset($this->linkElementTypes[$key])
+ && $this->linkElementTypes[$key] == 'radio';
if (isset($this->enumOptions[$key])) {
$options = $this->enumOptions[$key];
@@ -1485,5 +1492,7 @@
if (in_array($key, $this->selectAddEmpty)
|| !($type & DB_DATAOBJECT_NOTNULL)) {
- $options = array('' => $this->selectAddEmptyLabel) + $options;
+ $options = array('' => $isRadio ?
+ $this->radioAddEmptyLabel :
+ $this->selectAddEmptyLabel) + $options;
}
if (!$options) {
@@ -1491,5 +1500,5 @@
}
$element = array();
- if (isset($this->linkElementTypes[$key]) && $this->linkElementTypes[$key] == 'radio') {
+ if ($isRadio) {
$element =& $this->_form->_createRadioButtons($key, $options);
} else {
[2006-08-17 13:50 UTC] list dot dhooge at gmail dot com
Additional explanation:
Up to now, it is possible to have an empty label in
addition to existing field values in a select element. If
a blank value is perfect for select, the result is quite
misleading when used with radio buttons: a radio button
with no text.
The workaround is to modify $selectAddEmptyLabel to
contain the radio text but IMO it is better to define 2
separate strings. This allows to define once for all the
layout for select and radio buttons. And then each DO can
choose to display as it prefers without having to care
about the rendering.
[2006-08-29 08:58 UTC] list dot dhooge at gmail dot com
Link to a colored, nicely presented version of the patch
http://www.phpfi.com/146840
[2006-08-30 07:55 UTC] list dot dhooge at gmail dot com
You're right. I forgot to mention that I extended FB to
create empty forms used to filter selected rows to display
in a datagrid. You can look at
http://www.phpfi.com/147073?lang=php to have a idea.
So I agree it isn't needed by the default form. But there
are other cases where it still might be useful. For
instance if you want to extend the form to allow the user
to leave a field as "unchanged", maybe when doing changes
to several records at a time. Of course, it can be put in
the extension class but it won't be so easy :-(
(I knew potions wasn't correct! And I should have guessed
it was more likely to be swapped letters...)