Gossamer Forum
Home : Products : Links 2.0 : Customization :

multiple selection for a field

Quote Reply
multiple selection for a field
how do i make a multiple selection with a field for the administration section?

i can't figure it out..

here is an example of what i am looking for..

the field:

CPU has 4 selections.. MIPS, SH3, SH4, and ARM.

I want to make it so it is possible to select more than one of these.. and it will display it on the detailed page all of the selected ones..

any idea?
Jerry
Quote Reply
Re: multiple selection for a field In reply to
ok.. i did it wrong.. i got it working using:

Code:
($db_select_fields{$db_cols[$db_cpu]} = $db_select_fields{'Mult-CPU'} = $db_select_fields{$db_cols[$db_cpu]});

woo hoo... Smile
Quote Reply
Re: multiple selection for a field In reply to
In links.def, change:

Code:
# Hash of column names to possible options. If you want to use a select form
# field, you can use &build_select_field in your HTML page. This routine will
# make a <SELECT> input tag using the following values:
%db_select_fields = (
isNew => 'Yes,No',
isPopular => 'Yes,No',
ReceiveMail => 'Yes,No'
);

to read:

Code:
# Hash of column names to possible options. If you want to use a select form
# field, you can use &build_select_field in your HTML page. This routine will
# make a <SELECT> input tag using the following values:
%db_select_fields = (
isNew => 'Yes,No',
isPopular => 'Yes,No',
ReceiveMail => 'Yes,No',
CPU => 'MIPS,SH3,SH4,ARM'
);

This assumes you have defined a field called CPU. The script will automatically create the necessary select field for you in the admin screen.
Quote Reply
Re: multiple selection for a field In reply to
That will only create a regular select field, though, not a multiple-select field. The key to this is in db_utils.pl, sub build_html_record_form, where you get the little gem:
Code:
$multiple ? ($name = "$field-$rec{$db_key}") : ($name = $field);
if ($db_select_fields{"Mult-$field"})
which clearly defines how to use multiple select fields, and which I clearly do not understand how to use. Smile

Hope this point in the right direction will lead somebody else to shed some light, though.

Phoenix
Quote Reply
Re: multiple selection for a field In reply to
Phoenix,

Actually, the code:

Code:
# Set the field name to field-key if we are doing multiple forms.
$multiple ? ($name = "$field-$rec{$db_key}") : ($name = $field);

is used to determine whether multiple forms are being displayed, not a multiple select list. The multiple select list is determined by the code:

Quote:
if ($db_select_fields{"Mult-$field"}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_select_field($field, $rec{$field}, $name, "MULTIPLE SIZE=3") . "</td></tr>\n"; }

So the trick is to figure out now to get $db_select_fields{"Mult-$field"} to be true. Frankly, it is hard-coded into db_utils.pl itself in the same subroutine. See the example for the Related fields just above that part of the code, where it says:

Quote:
$db_select_fields{'Related'} or
($db_select_fields{'Related'} = $db_select_fields{'Mult-Related'} = join ",", &category_list);

So, I assume if he wants to make the CPU field a multiple select list, he would also have to add this just below the "related" lines:

Quote:
$db_select_fields{'CPU'} or
($db_select_fields{'CPU'} = $db_select_fields{'Mult-CPU'};

Then the script would build his multiple select field, I think (I haven't actually tested it).
Quote Reply
Re: multiple selection for a field In reply to
Thanks, Bobsie. I'm probably going to end up needing this too (eventually) so I was interested to see what came of it.

I was starting to get the idea that it had to be hard-coded into db_utils.pl, but I wasn't sure because of the bit about limiting the number of times the category list is loaded or some such.

I was just aiming for the ($db_select_fields{"Mult-$field"}) bit, because that tells me something about how a select field has to be defined for Links to recognize it and build it as a Multi-select.

The more I look at it, the less I understand how to use it. Smile I'm tired.

Phoenix
Quote Reply
Re: multiple selection for a field In reply to
I tried to test my theory and it didn't work, so I am trial and erroring it some more. I'll let you know what I find.
Quote Reply
Re: multiple selection for a field In reply to
Okay, here is how to do a multiple select list in the admin screen. Instead of putting the code in %db_select_fields as I posted previously, go to db_utils.pl, sub build_html_record_form, and change this:

Code:
if ($in{'db'} eq 'links') {
exists $db_select_fields{$db_cols[$db_category]}
or ($db_select_fields{$db_cols[$db_category]} = join (",", &category_list));
}

to read:

Code:
if ($in{'db'} eq 'links') {
exists $db_select_fields{$db_cols[$db_category]}
or ($db_select_fields{$db_cols[$db_category]} = join (",", &category_list));
$db_select_fields{'CPU'} or
($db_select_fields{'CPU'} = $db_select_fields{'Mult-CPU'} = 'MIPS,SH3,SH4,ARM');

So, the rule of thumb is, for a regular select list, use %db_select_fields in links.def or category.def. For multiple select list, hard-code it in db_utils.pl, sub build_html_record_form.

I hope this helps.

[This message has been edited by Bobsie (edited July 06, 1999).]
Quote Reply
Re: multiple selection for a field In reply to
Thanks again, Bobsie. You didn't have to go and do that.

I appreciate the help.
Phoenix
Quote Reply
Re: multiple selection for a field In reply to
Yes I did have to. Otherwise, it would keep me awake nights (or is that days? I forget).
Quote Reply
Re: multiple selection for a field In reply to
If Links works as DBMan, an alternative - and perhaps easier? - solution might be to use checkbox selections, which allow multiple selections.

To add checkboxes, see:
www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/000520.html

And then ... do something in links.def ....

Oh well, just a thought ;-)

PS: How do you make the smiley icons??

[This message has been edited by gotze (edited July 06, 1999).]
Quote Reply
Re: multiple selection for a field In reply to
John, Thanks for the suggestion. That's another alternative I've been thinking of. I'm not sure yet which will best suit my needs, as far as ease of maintenance.

As for the smilies, click the "faq" link in the upper right of this page.

Phoenix
Quote Reply
Re: multiple selection for a field In reply to
OMG! Smile

I had been doing that all the time! lol.. but I just didn't put the right thing at the end..

($db_select_fields{'CPU'} = $db_select_fields{'Mult-CPU'} = 'MIPS,SH3,SH4,ARM');

hmm... is there anyway to make it so it will go to links.def and get the variables from the %db_select_fields? (i will try and do it myself..) but shouldn't it be like:

Code:
($db_select_fields{'CPU'} = $db_select_fields{'Mult-CPU'} = '$db_select_fields{'CPU'}');

cause $db_select_fields{'CPU'} gives you the data from the key "CPU" from %db_select_fields

?? any chance.. and btw bobsie.. you are great! how come you do this for free... lol

wait.. i'm not giving you any ideas now... don't read that!!! lol
Quote Reply
Re: multiple selection for a field In reply to
widgets,

I guess that will work as well but take another look at my code:

Code:
$db_select_fields{'CPU'} or
($db_select_fields{'CPU'} = $db_select_fields{'Mult-CPU'} = 'MIPS,SH3,SH4,ARM');

That code checks to see if the field is defined in %db_select_fields and if it is, it will build a normal select list. Otherwise, it creates a multiple select list. So I wouldn't include the list of choices in %db_select_fields. Instead, I would create a new variable in links.def that looks something like this:

Code:
$db_select_fields{'CPU'} or
($db_select_fields{'CPU'} = $db_select_fields{'Mult-CPU'} = %CPU_select;

That would maintain consistency in the code. As any Perl programmer will tell you, there is more than one way to do it. Smile

[This message has been edited by Bobsie (edited July 06, 1999).]
Quote Reply
Re: multiple selection for a field In reply to
i just left out:

Code:
$db_select_fields{'CPU'} or

(the first line)
so it wouldn't do it..