Date: 01/03/01
- Next message: Jeroen Laarhoven: "[phplib-dev] Forms"
- Previous message: uw: "[phplib-dev] cvs commit"
- Next in thread: uw: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: uw
Date: Thu Jan 4 01:08:15 2001
Modified files:
php-lib/pages/form/example_form.inc
php-lib/php/form/form_element_combo.inc
Log message:
- added "add option" to the combo box
A combo box is one of the new compound form element types.
It consists of a select box, a text input field and an optional
"add option" button. If the user hits the "add option" button the new
option gets inserted at the beginning of the select box option list.
Warning: the form API for Combo boxes might change slightly in future
versions.
- updated the demo
Index: php-lib/pages/form/example_form.inc
diff -u php-lib/pages/form/example_form.inc:1.4 php-lib/pages/form/example_form.inc:1.5
--- php-lib/pages/form/example_form.inc:1.4 Mon Jan 1 16:01:05 2001
+++ php-lib/pages/form/example_form.inc Thu Jan 4 01:07:34 2001
@@ -150,7 +150,7 @@
)
);
-/*
+
$this->addElement(
array (
"name" => "combo",
@@ -174,10 +174,13 @@
"maxlength" => 40,
"length_e" => "The new entry gets refused. It must be 3 to 40 characters long.",
- "frozen" => false
+ "frozen" => false,
+
+ "add" => "add entry"
+
)
);
-
+/*
$this->addElement(
array (
"name" => "treeview",
@@ -373,13 +376,16 @@
"frozen" => false
)
);
-/*
+
$this->addElement(
array (
"name" => "date_en",
"type" => "date",
- "format" => "Y-m-d D/F/l/A/M",
- "language" => "en"
+ "format" => "g Y-m-d D/F/l/A/M",
+ "language" => "en",
+ "now" => "now",
+ "intro" => "-%-",
+ "intro_e" => "Please select an option."
)
);
@@ -388,11 +394,15 @@
array (
"name" => "date_de",
"type" => "date",
- "format" => "H:i:s D/F/l/A/M",
- "language" => "de"
+ "format" => "aAdDFhHgGijlmnMswYyz",
+ "language" => "de",
+ "now" => "jetzt",
+ "preload" => true,
+ "intro" => "-%-",
+ "intro_e" => "Please select an option."
)
);
-*/
+
// autoload the form with HTTP_[POST|GET]_VARS
$this->autoloadValues();
Index: php-lib/php/form/form_element_combo.inc
diff -u php-lib/php/form/form_element_combo.inc:1.7 php-lib/php/form/form_element_combo.inc:1.8
--- php-lib/php/form/form_element_combo.inc:1.7 Tue Jan 2 16:49:32 2001
+++ php-lib/php/form/form_element_combo.inc Thu Jan 4 01:07:40 2001
@@ -4,7 +4,7 @@
*
* <email protected> Ulf Wendel <uw <email protected>>
* <email protected> Form
-* <email protected> $Id: form_element_combo.inc,v 1.7 2001/01/02 15:49:32 uw Exp $
+* <email protected> $Id: form_element_combo.inc,v 1.8 2001/01/04 00:07:40 uw Exp $
*/
class form_element_combo extends form_element_selectobject {
@@ -28,7 +28,9 @@
"valid_e" => "string",
"readonly" => "boolean",
- "sort" => "string"
+ "sort" => "string",
+
+ "add" => "string"
);
/**
@@ -111,7 +113,7 @@
* but you can choose to sort them in alphabetical order
* or reverse alphabetical order eighter.
*
- * <email protected> string s"top" (default) means enter new entries as
+ * <email protected> string "top" (default) means enter new entries as
* the first entry in the select box option
* list, "up" means sort them alphabetical and
* "down" sort them in reverse alphabetical order.
@@ -128,6 +130,17 @@
var $sort_icase = true;
/**
+ * Caption of the add option button.
+ *
+ * If the add attribute is set and the form has a JavaScript name
+ * the combo element will consist of three elements: a select box,
+ * a text input field and a "add option" button.
+ *
+ * <email protected> string
+ */
+ var $add = "";
+
+ /**
* Validates the value of the text input field ( = new combo option )
*
* <email protected> boolean array $error[0] = $ok, $error[1] = $messages
@@ -135,10 +148,10 @@
*/
function validateTextInputEntry() {
- if (!isset($GLOBALS["combo_" . $this->name]))
+ if (!isset($GLOBALS[$this->name . "_comboinput"]))
return array(false, "");
- $userentry = $GLOBALS["combo_" . $this->name];
+ $userentry = $GLOBALS[$this->name . "_comboinput"];
$message = $this->validateLength($userentry) . $this->validateRegEx($userentry);
$ok = ("" == $message) ? true : false;
@@ -155,7 +168,7 @@
list($ok, $message) = $this->validateTextInputEntry();
- return ($ok) ? $GLOBALS["combo_" . $this->name] : "";
+ return ($ok) ? $GLOBALS[$this->name . "_comboinput"] : "";
} // end func getNewComboOption
/**
@@ -193,12 +206,13 @@
} else {
// Does anybody know a better way?
+ // array_unshift does not do the trick.
$tmp = array();
- $tmp[$value] = $label;
+ $tmp[$value] = $label;
foreach ($this->options as $k => $v)
$tmp[$k] = $v;
-
+
$this->options = $tmp;
}
@@ -273,6 +287,8 @@
if (true == $this->flag_frozen)
return $this->getfrozen($value);
+ // we start with the select box
+
$html = sprintf('<select name="%s" ', $this->name);
if ("" != $this->size)
@@ -286,6 +302,7 @@
$html .= $this->getCommonHTMLAttributes();
$html .= $this->getJSonActivation();
+
$html = substr($html, 0, -1) . ">" . $this->CR_HTML;
$html .= $this->getIntroOptionTags();
@@ -293,9 +310,11 @@
$html .= $this->getOptionTags();
$html .= "</select>";
-
+
+ // now the input field
+
$html .= '<input type="text" value="" ';
- $html .= sprintf('name="combo_%s" ', $this->name );
+ $html .= sprintf('name="%s_comboinput" ', $this->name );
if ($this->inputsize >= 0)
$html .= sprintf('size="%d" ', $this->inputsize);
@@ -312,10 +331,66 @@
$html .= sprintf('%s ', $this->additional_html);
$html .= $this->getJSonActivation();
+ $html = substr($html, 0 , -1) . ">";
+
+ // add option button
+
+ if ($this->add && $this->form_name)
+ $html .= sprintf('<input type="submit" name="%s_combosubmit" value="%s" onClick="form_combo_add(\'%s\'); return false">',
+ $this->name,
+ $this->add,
+ $this->name
+ );
- return substr($html, 0, -1) . ">" . $this->CR_HTML;
+ return $html . $this->CR_HTML;
} // end func get
+ function getExtraJS() {
+
+ $js = sprintf('function form_combo_add(e) {
+ var o, t, i, s, so, j;
+
+ so = document.forms["%s"].elements["%s_comboinput"];
+ s = so.value;
+ t = [];
+
+ with (document.forms["%s"].elements[e]) {
+
+ for (i = 0; i < options.length; i++) {
+
+ o = options[i].text;
+ if (o == s) {
+ options[i].selected = true;
+ so.value = "";
+ return;
+ }
+
+ t[i] = [o, options[i].value];
+ }
+
+ options.length = 0;
+ options[0] = new Option(s, s, false, true);
+ for (j = 0; j < i; j++)
+ options[j + 1] = new Option(t[j][0], t[j][1], false, false);
+
+ }
+
+ so.value = "";
+ document.forms["%s"].elements[e].selectedIndex = 0;
+}',
+ $this->form_name,
+ $this->name,
+ $this->form_name,
+ $this->form_name
+ );
+
+ return array($js, "form_combo_add");
+ } // end func getExtraJS
+
+ function getJSValue() {
+ return form_element_select::getJSValue();
+ }
+
function validate() {
return $this->validateTextInputEntry() . $this->validateIntro();
} // end func validate
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected>
For additional commands, e-mail: phplib-dev-help <email protected>
- Next message: Jeroen Laarhoven: "[phplib-dev] Forms"
- Previous message: uw: "[phplib-dev] cvs commit"
- Next in thread: uw: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

