Hello Folks,
I am using a callout to populate a text field pls find the ipl below.
What it does is it gives me a list of values from a txt file so i can select it for my text field.
What i want to do is when i enter something in the Text Field, lets say Account and click the callout button it should show me only the values like Account* and nothing else in the list box so i cant select from the few options i have...Its more or less like a search...
Can someone help me with what changes i need to nmake in the ipl.
I am using my $item_value = $cgi->{form}{Text}; and trying to do pattern matching ...Is that the right way at all...Pls explain.
#################CALL FROM THE DATACAPTURE.CFG######################
<cgi-callout url="/iw-bin/iw_cgi_wrapper.cgi/datacapture_callout.ipl/test.txt" label="Search" window-features="width=800,height=600,scrollbars=yes,resizable=yes,status=yes,location=yes"/>
################IPL FILE##############
use TeamSite::CGI_lite;
use TeamSite::Config;
$|=1;
my $cgi = TeamSite::CGI_lite->new();
$cgi->parse_data();
my $form_name = $cgi->{'form'}{'iw_form_name'};
my $element_name = $cgi->{'form'}{'iw_callback_var'};
my $user_name = $cgi->{'form'}{'user_name'};
my $item_name = $cgi->{'form'}{'iw_item_name'};
my $item_value = $cgi->{form}{Text};
my $item_description = $cgi->{'form'}{'iw_item_description'};
my $dcr_name = $cgi->{'form'}{'iw_object_name'};
my $flat_file = $ENV{'PATH_INFO'};
if ($flat_file =~ m!^.*/([^/]+)$!) {
$flat_file = $1;
}
my
@options = parse_flat_file( make_full_filename( $flat_file ) );
if (!
@options){
error_message( 'No available selection options were found.' );
exit 1;
}
print_ui(
@options );
exit 0;
sub make_full_filename {
my ($filename) =
@_;
my $full_filename = TeamSite::Config::iwgetlocation("iwconfigs") . "/" . $filename;
return $full_filename;
}
sub parse_flat_file {
my ($filename) =
@_;
my
@options;
if ((-f $filename) && (open( FILE, $filename )))
{
while (<FILE>)
{
my $line = $_;
if ($line =~ /^([^,]*),(.*)$/)
{
my %hash = ( 'value' => $1, 'label' => $2);
push(
@options, \%hash );
@options = grep(/^($item_value)*/,
@options) }
}
}
close FILE;
return
@options;
}
sub print_ui {
my (
@options) =
@_;
print_header();
print <<"END";
<FORM NAME="callout_form">
<TABLE BORDER="0" CELLPADDING="0" ALIGN="CENTER">
<TR>
<TD VALIGN="TOP" WIDTH="150">
<FONT SIZE="-1">$item_name</FONT>
<BR>
<FONT SIZE="-1"><EM>$item_description</EM></FONT>
</TD>
<TD VALIGN="TOP">
<SELECT NAME="selection_list">
END
foreach my $hash (
@options) {
my $value = $hash->{'value'};
my $label = $hash->{'label'};
if ($label eq '')
{
$label = $value;
}
print "<OPTION VALUE=\"$value\">$label</OPTION>\n";
}
print <<"END";
</SELECT>
</TD>
</TR>
</TABLE>
<CENTER>
<INPUT TYPE="BUTTON" VALUE="OK" onClick="handle_selection()">
<INPUT TYPE="BUTTON" VALUE="Cancel" onClick="self.close()">
</CENTER>
</FORM>
END
print_footer();
return;
}
sub error_message {
my (
@msgs) =
@_;
print_header();
foreach my $message (
@msgs) {
print $message;
}
print <<"END";
<CENTER>
<FORM>
<INPUT TYPE="BUTTON" VALUE="OK" onClick="self.close()">
</FORM>
</CENTER>
END
print_footer();
return;
}
sub print_header {
print<<"END";
Content-type: text/html
<HTML>
<HEAD>
<TITLE>Datacapture Callout</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function set_datacapture_item_value( selectedValue )
{
if ((window.opener == null) ||
(window.opener.closed))
{
return false;
}
var calloutForm = eval($form_name);
if (!calloutForm)
{
return false;
}
var calloutElementFound = false;
for ( i = 0 ; i < calloutForm.elements.length ; i++ )
{
if (calloutForm.elements
.name == '$element_name')
{
calloutForm.elements.value = selectedValue;
calloutElementFound = true;
break;
}
}
if (!calloutElementFound)
{
return false;
}
return true;
}
function handle_selection()
{
if (callback())
{
if(opener.top.datacapture) {
opener.top.datacapture.refreshForm();
}
self.close();
}
else
{
alert('Please make a selection.');
}
}
function callback()
{
var optionsArray = document.callout_form.selection_list.options;
for ( i = 0 ; i < optionsArray.length ; i++ )
{
if (optionsArray.selected)
{
if (!set_datacapture_item_value( optionsArray.value ))
{
alert('Fatal callout error. Did you close the datacapture window?');
}
return true;
}
}
// did not find a selected option!
return false;
}
// -->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<TABLE BORDER=0 cellpadding=0 cellspacing=0 WIDTH=100%>
<TR>
<TD ALIGN="LEFT"><B>Example Datacapture Callout</B><BR>
<FONT SIZE="-1"><B>Name: $dcr_name</B></FONT><BR></TD>
<TD ALIGN="RIGHT" VALIGN="TOP"><IMG src="/iw-cc/formspub/images/logo.gif"></TD>
</TR>
</TABLE>
END
return;
}
sub print_footer {
print <<"END";
</BODY>
</HTML>
END
return;
}