I'm not sure if this code will play nice with everyone else, but I've made changes to <f:single-select/> and <f:multi-select/> that adds:

- Default setting support
- Index support to allow multiple select fields of the same name
- Population of options through XML elements

The main reason I've done this, is because I needed to define multiple single-select fields on one form (see my similar post on axkit-users). I figured while I was in there, I could make it easier to use.

Here's some example code to show how it works:

<f:single-select name="language" index="1" default="en-US">
<f:options>
<option>
<name>English</name>
<value>en-US</value>
</option>
<option>
<name>Redneck</name>
<value>rn-US</value>
</option>
<option>
<name>French</name>
<value>fr</value>
</option>
</f:options>
</f:single-select>

I've only tested single-select, but it plays well with ESQL (the above code was typed into my email proggie, so it hasn't been run, but my PerForm/ESQL XSP code is pretty damned verbose. If you want the full deal, lemme know and I'll send the example of what I'm running).

AFAIK, from the way I wrote this, the multi-select can have multiple default values, ala:

<f:multi-select name="foo">
<f:default>1</f:default>
<f:default>5</f:default>
</f:multi-select>

If I did anything wrong, please let me know (it's pretty damned late in my timezone, so I might've made some stupid mistakes).

Just in case axkit-devel rejects my attachment, I've dumped the patch on my site at:

http://nachbaur.com/resources/axkit/perform-select.patch

--

-man
Michael A Nachbaur
The best way to predict the Future is to invent it.

PGP Public Key at http://www.nachbaur.com/pgpkey.asc
PGP Key fingerprint = 83DC 7C3A 3084 6A21 9A3F 801E D974 AFB4 BFD7 2B6F
--- /home/nachbaur/.cpan/build/AxKit-XSP-PerForm-1.6/PerForm.pm Tue Jun 11 00:43:00 
2002
+++ /usr/lib/perl5/site_perl/5.6.0/AxKit/XSP/PerForm.pm Sat Nov  2 01:15:25 2002
@@ -22,8 +22,8 @@
     'file_upload($name;$value,$accept)',
     'hidden($name;$value,$index)',
     'textarea($name;$cols,$rows,$wrap,$default,$index)',
-    'single_select($name):itemtag=option',
-    'multi_select($name):itemtag=option',
+    'single_select($name;$default,$index,*options):itemtag=option',
+    'multi_select($name;@default,$index,*option):itemtag=option',
 );
 
 use strict;
@@ -426,8 +426,8 @@
     };
 }
 
-sub multi_select ($) {
-    my ($name) = @_;
+sub multi_select ($;$$$) {
+    my ($name, $default, $index, $option) = @_;
     my ($package) = caller;
     
     no strict 'refs';
@@ -442,7 +442,7 @@
     if ($params->{'__submitting'}) {
         if (defined &{"${package}::validate_${name}"}) {
             eval {
-                "${package}::validate_${name}"->($ctxt, [$params->get($name)]);
+                "${package}::validate_${name}"->($ctxt, [$params->get($name.$index)], 
+$index);
             };
             $error = $@;
             $ctxt->{_Failed}++ if $error;
@@ -453,7 +453,11 @@
     # load
     my ($selected, @options);
     if (defined &{"${package}::load_${name}"}) {
-        ($selected, @options) = "${package}::load_${name}"->($ctxt, 
[$params->get($name)]);
+        ($selected, @options) = "${package}::load_${name}"->($ctxt, 
+[$params->get($name.$index)], $default, $index);
+    }
+    elsif (!$params->{'__submitting'}) {
+        $selected = [@{$default}];
+        @options = map { $$_{name}, $$_{value} } @{$option};
     }
     
     my %selected = map { $_ => 1 } @$selected;
@@ -469,6 +473,7 @@
         multi_select => {
             name => $name,
             ($error ? ( error => $error ) : ()),
+           index => $index,
             options => [
                 map {
                   { 
@@ -541,8 +546,8 @@
     };
 }
 
-sub single_select ($) {
-    my ($name) = @_;
+sub single_select ($$$$) {
+    my ($name, $default, $index, $option) = @_;
     my ($package) = caller;
     
     no strict 'refs';
@@ -557,7 +562,7 @@
     if ($params->{'__submitting'}) {
         if (defined &{"${package}::validate_${name}"}) {
             eval {
-                "${package}::validate_${name}"->($ctxt, $params->{$name});
+                "${package}::validate_${name}"->($ctxt, $params->{$name.$index}, 
+$index);
             };
             $error = $@;
             $ctxt->{_Failed}++ if $error;
@@ -568,7 +573,11 @@
     # load
     my ($selected, @options);
     if (defined &{"${package}::load_${name}"}) {
-        ($selected, @options) = "${package}::load_${name}"->($ctxt, $params->{$name});
+        ($selected, @options) = "${package}::load_${name}"->($ctxt, 
+$params->{$name.$index}, $default, $index);
+    }
+    elsif (!$params->{'__submitting'}) {
+        $selected = $default;
+        @options = map { $$_{name}, $$_{value} } @{$option};
     }
     
     my (@keys, @vals);
@@ -582,6 +591,7 @@
         single_select => {
             name => $name,
             ($error ? ( error => $error ) : ()),
+           index => $index,
             options => [
                 map {
                   { 
@@ -814,7 +824,7 @@
 triggered (as part of the submission procedure) and the browser will redirect to a 
page
 that handles the purchase of the associated item.
 
-NOTE: arrays not supported for multi-select, single-select or file-upload elements.
+NOTE: arrays not supported for file-upload elements.
 
 =head1 TAG DOCUMENTATION
 
@@ -868,8 +878,9 @@
 
 =back
 
-Note that <f:form> is the B<only> tag in PerForm that has content. All other tags are 
empty,
-unless you define the attributes in child tags, as documented above.
+Note that <f:form> is the B<only> tag (besides <f:single-select/> and 
+<f:multi-select/>)
+in PerForm that has content. All other tags are empty, unless you define the 
+attributes
+in child tags, as documented above.
 
 =head2 <f:submit/>
 
@@ -1248,7 +1259,8 @@
 
 A drop-down select list of items.
 
-Both single-select and multi-select (below) are populated solely by callbacks.
+The single-select and multi-select (below) elements can be populated either by 
+callbacks
+or through embedded elements.
 
 B<Attributes:>
 
@@ -1258,6 +1270,37 @@
 
 The name of the single select widget.
 
+=item default
+
+The default value that is to be selected.
+
+=item index
+
+Use this to identify the array index when using arrayed form elements.
+
+=back
+
+B<Elements:>
+
+=over 4
+
+=item <f:options>
+
+Child to a <f:single-select> element, this wraps around a listing of
+populated options
+
+=item <option>
+
+Child to <f:options>, this is an individual option
+
+=item <name>
+
+This is the name for a given option, to which it is a child
+
+=item <value>
+
+Similar to <name>, this indicates the value for an option
+
 =back
 
 B<Callbacks:>
@@ -1300,7 +1343,22 @@
 
 The name of the multiple select widget.
 
+=item default
+
+The default value that is to be selected.  This can be specified as
+a child element (e.g. <f:default>) in order to indicate multiple
+default values.
+
+=item index
+
+Use this to identify the array index when using arrayed form elements.
+
 =back
+
+B<Elements:>
+
+The available child elements are identical to <f:single-select> so they will
+not be repeated here.
 
 B<Callbacks:>
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to