I'm trying to implement a nested dropdown menu. I have partially done it.
The following code is CGI script which gets information from a database and fills dropdown1 (JsonAPI Dynamic field).
Question is how to get a selected value in dropdown1 and used it to make database query and fill dropdown2?
Code: Select all
#!/usr/bin/perl -w
use strict;
use warnings;
use CGI qw(:standard);
#use JSON; #install JSON via cpan/ppm if you want to use it instead
print header(-type => 'application/json');
#code to query data
# use ../../ as lib location
use FindBin qw($Bin);
use lib "$Bin/../..";
use lib "$Bin/../../Kernel/cpan-lib";
use lib "$Bin/../../Custom";
use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Main;
use Kernel::System::DB;
use Kernel::System::ObjectManager;
use JSON;
use Data::Dumper;
local $Kernel::OM = Kernel::System::ObjectManager->new();
my %CommonObject = ();
$CommonObject{ConfigObject} = Kernel::Config->new();
$CommonObject{EncodeObject} = Kernel::System::Encode->new(%CommonObject);
$CommonObject{LogObject} = Kernel::System::Log->new(
LogPrefix => 'ExtData',
%CommonObject,
);
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
$CommonObject{DBObject} = Kernel::System::DB->new(
%CommonObject,
DatabaseDSN => 'DBI:Pg:database=sandbox;host=host;',
DatabaseUser => 'user',
DatabasePw => 'password',
Type => 'postgresql',
);
# my $query = param('q') || '';
my $ResultAsArrayRef = $CommonObject{DBObject}->Prepare(
SQL => 'SELECT distinct region, region FROM public.sites',
Order => 'asc'
);
# my $json = JSON->new;
# $json = JSON->new->allow_nonref;
#my $json_text = JSON->new;
#$json_text = to_json($ResultAsArrayRef);
#$json_text = $json->encode($ResultAsArrayRef);
#print Dumper ($json_text);
#print Dumper ($ResultAsArrayRef);
#print($json_text);
print('{"TBLS":{"Key":"TBLS", "Value":"Tbilisi"}, "IMRT":{"Key":"IMRT", "Value":"Imereti"}}');
1;