Gossamer Forum
Home : Products : DBMan : Installation :

how to use multiple select fields

Quote Reply
how to use multiple select fields
I need to have several values in one field like say 1~~2~~3
First of all I just repeated select field for this field two more times in the form (in html.pl).
It works fine when I add a new entry but when I try to modify an entry it turns out that all three fields have the first value selected i.e. 1 1 1
It makes me think that I did something wrong this time. Any suggestions?
Quote Reply
Re: how to use multiple select fields In reply to
The following is from the Links script:

Code:
sub build_select_field {
# --------------------------------------------------------
# Builds a SELECT field based on information found
# in the database definition. Parameters are the column to build,
# a default value, a default name, whether to allow multiple selections,
# and the size of the box.
my ($column, $value, $name, $mult, $size) = @_;
my (@fields, @values, $ouptut);
$name | | ($name = $column);
$size | | ($size = 1);
if ($mult) { @values = split (/\Q$db_delim\E/,$value); }
else { @values = ($value); }
@fields = split (/\,/, $db_select_fields{$column});
if (! exists ($db_select_fields{$column})) {
$output = "error building select field: no fields specified/unkown field ($column)!";
}
else {
$output = qq|<SELECT NAME="$name" $mult SIZE=$size><OPTION>---|;
foreach $field (sort @fields) {
if (grep $_ eq $field, @values) {
$output .= "<OPTION SELECTED>$field\n";
}
else {
$output .= "<OPTION>$field";
}
}
$output .= "</SELECT>";
}
return $output;
}

If you replace this with the build_select_field subroutine in db.cgi, you can build your regular select fields the same way as you always have --

&build_select_field("fieldname","$rec{'fieldname'})

But if you want one to be a multiple select field, call it by using

&build_select_field("fieldname","$rec{'fieldname'},"fieldname","MULTIPLE",3)

You can change the 3 above to whatever size you want for the select field.

I've used this and it works great for me.


------------------
JPD





Quote Reply
Re: how to use multiple select fields In reply to
Thanks for advise - now I know that I'm not alone
I just tried this - no fun. Frown
Premature end of you know what
I suspect that to replace only this bit of db.cgi isn't enough. It seems that you've forgotten to mention something essential.
Help PLS
Quote Reply
Re: how to use multiple select fields In reply to
The only thing it could be (which I did forget to mention) is that here on the forum when there's two | characters, for some reason it inserts a space between them. So on the lines

$name &#0124; &#0124; ($name = $column);
$size &#0124; &#0124; ($size = 1);

take out the space between the | characters.


------------------
JPD





Quote Reply
Re: how to use multiple select fields In reply to
Yepp, thanks a lot!
This was the case. I removed spaces and it worked.
Though, what I've got as a result isn' exactly what I wanted. There is a scrollable select form but the problem is that I can only select ADJASCENT values. What if I want to take one from the top and one from the bottom. I really need it. Say, I have 1~~2~~3 and I need to replace it with 3~~4~~9 via the Modify form. Or a user needs to get results like 3AND6AND1. How do I do this? Or this is just impossible (than why multiple function was implemented at all)?

But thank you anyway!
Quote Reply
Re: how to use multiple select fields In reply to
Hell,
Sorry, I just forgot about the Ctrl key.
My fault. Now I see how silly was my previous posting.
Sorry, and thanks again.
Quote Reply
Re: how to use multiple select fields In reply to
Now another problem
when I do multiple select it searches AND
Is there a way to make it OR?
Quote Reply
Re: how to use multiple select fields In reply to
Not that I know of. When I use a multiple select field, I use it only on the "add" form. On the search form, I restrict it to one selection.

Sorry I couldn't be of more help.


------------------
JPD





Quote Reply
Re: how to use multiple select fields In reply to
JPDeni,

When I use the above code to build my multiple select field, no matter what value I change the field size(3) parameter to, it still gives me the scrollable listing with the first 3 option in the select list displayed.

Any ideas why..?
Quote Reply
Re: how to use multiple select fields In reply to
Sorry, I don't know why. I haven't played around much with multiple select fields, so I'm not sure about how they work in html.



------------------
JPD