Gossamer Forum
Home : Products : DBMan : Customization :

Select Field

Quote Reply
Select Field
I've got a problem with the displayed size of a select field.

I followed Eliots earlier advice, and used the mod from

http://www.gossamer-threads.com/scripts/forum/resources/Forum5/HTML/001373.html


to build a select field from a second .db

Works GREAT --- but the field from the second db is a set of text comments (sometimes quite looonng). This makes the select field looonng, and unsuitable to the page layout.

Ideally, I'd be able to select a short comment description, or a number associated with the actual text comment (from a different shorter field in the second db).

At the least, I need to limit the DISPLAYED portion of the text comment to the first 40? characters. NOT chop off the actual data, only the display. Or maybe show the field in a text area.

I've tried to come up with a solution on my own, but with no good result.

Help - Suggestions - Anyone!

Fred
Quote Reply
Re: Select Field In reply to
Hey,

I am not entirely sure what you are trying to do. But, if I am right, you are trying to pick a word like "apple" from a list in the form, and then when the record is written, what is displayed is not "apple" but. "A round tasty fruit, juicy center and bright red skin etc...."

If this is what you are doing, it is very easy to do!

Just add something like to your default.cfg file.

Code:


# Select fields. Field name => 'comma seperated list of drop down options'.
%db_select_fields = (

Fruit=> 'Apple,Orange'
);

$text{'Apple'} = "A round tasty fruit, juicy center and bright red skin.";

$text{'Orange'} = "Round, very juicy fruit that is orange is color and yummy.";

also be sure to add a line like this to your default.cfg file.
Code:
Fruit => [13, 'alpha', 0, 255, 1, '', ''],


You should be able to figure out the rest on your own! Good luck, and let me know if it works.


dataKing



------------------
Well that depends what the meaning of "is" is...
Quote Reply
Re: Select Field In reply to
Hey dataKing,
Thanks for the input. That is what I'm trying to do, except that the select field is built from fields in the second db. This is the sub in the db.cgi
Code:
sub build_select_field_from_other_db {
# ------------------------------------------
# Builds a SELECT field from the database.
my ($column, $value) = @_;
my (@fields, $field, @selectfields, @lines, $line, $ouptut);
my ($fieldnum, $found, $i) = 0; open (DB, "<$db_other_file_name") or &cgierr("unable to open $db_other_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); } LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields [$other_fieldnum], @selectfields)) {
push (@selectfields, $fields[$other_fieldnum]);
}
}
close DB;

$output = qq|<SELECT NAME="$name"><OPTION>---|;
foreach $field (sort @selectfields) {
($field eq $value) ?
($output .= "<OPTION SELECTED>$field") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";
return $output;
}

and this is the code in html_record_form that calls it
Code:
<tr><td>Name:</td>
&nbsp<td> |;
print &build_select_field_from_other_db("Name",$rec{'Name'});
print qq|</td></tr>

I can't figure out how to get the equivalent of your
Code:
Fruit=>apple,orange
Help!


[This message has been edited by Fred (edited October 29, 1999).]
Quote Reply
Re: Select Field In reply to
Any alternate suggestions on how to accomplish this are appreciated
Fred