Hi Guys,
I can't manage to make a correct jQuery select2 script that can filter a drop down based on a user choice from previous drop down and an additional filter parameter obtained by ajax request from another table. Actually I just only need to use the second filter parameter (ID), obtained with Ajax but first the user must make a choice in the first drop down. I saw how to update text fields with Ajax and select2 from UDEMY but for the drop downs it looks more complex and I don't know how to do it.
Filter a drop down with parameter obtained with Ajax
Re: Filter a drop down with parameter obtained with Ajax
Guys,
I have finally figure it out.
ajax-nomenclature-type.php:
This comes with a parasite field that I had to make because AppGini generates different versions of the function nomanclature_debit_reload when the field nomanclature_debit is not defined as filtered by another field. Without it you cant call nomanclature_debit_reload(data) because the function does not accept a parameter. So I just made this lookup nomanclature_type_debit that filters the nomanclature_debit and hide it from DV and TV. Not the best solution but it works and now I don't need to choose from 3 consecutive drop downs but only two. This is all good cause otherwise in my case in the second one there is always just one option.
I have finally figure it out.
Code: Select all
$j('#debit_account-container').on('change', function(e){
var account_id = e.added.id;
//console.log(account_id);
if(account_id == '<Ðищо>'){
$j('#nomenclature_debit').val('');
}else{
$j.ajax({
url: 'hooks/ajax-nomenclature-type.php',
data: { account_id: account_id },
success: function(data){
nomanclature_debit_reload(data);
}
});
}
});
Code: Select all
<?php
$currDir = dirname(__FILE__) . '/..';
include("$currDir/defaultLang.php");
include("$currDir/language.php");
include("$currDir/lib.php");
/* grant access to all users who have acess to the accountplan table */
$od_from = get_sql_from('accountplan');
if(!$od_from){
header('HTTP/1.0 401 Unauthorized');
exit;
}
$account_id = intval($_REQUEST['account_id']);
$nomenclature_type_id = sqlValue("SELECT nomenclature_type FROM accountplan WHERE id='{$account_id}'");
echo $nomenclature_type_id;
?>
- Attachments
-
- screenshot
- credit_mo.png (158.61 KiB) Viewed 2320 times
Re: Filter a drop down with parameter obtained with Ajax
Thanks for sharing
AppGini plugins to add more power to your apps:
- DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
- Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
- Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.