Joomla.it Forum

Non solo Joomla... => Database => : andrea 20 Apr 2009, 19:54:38

: Fabrik realizzare due combo in cascata
: andrea 20 Apr 2009, 19:54:38
Salve ragazzi, qualcuno di voi sà come è possibile con codice javascript personalizzato mettere due dropdownmenu in cascata in fabrik?

Io non conosco javascript ma devo far diventare il valore scritto dentro il primo dropdown l'argomento di un filtro query sul secondo dropdown
: Re: Fabrik realizzare due combo in cascata
: andrea 22 Apr 2009, 12:10:50
ok ragazzi..ci sono vicino però non riesco a capire perchè il secondo combo viene aggiornato con un valore null.

Posto i codici della chiamata ajax e del plugin ajax utilizzato..

Chiamata :

:
var cid = this.getValue();
var table = 'Campi';
var key = 'Nomecampo';
var label = 'Nomecampo';
var foreignkey = 'Tipocampo';

var dropdown = 'Registrazione___Campo';

var url = 'index2.php?option=com_fabrik&no_html=1&task=userPluginAjax&method=getFields';

url += '&table=' + table;
url += '&val='+cid;

url += '&key='+key;

url += '&label='+label;

url += '&foreignkey='+foreignkey;

new Ajax(url, {
method: 'get',
update: $(dropdown)
}

).request();

Modulo ajax :
:
/* MOS Intruder Alerts */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

class userAjax {

function getFields(){
global $database;
//get all the variables passed in by the ajax objects url
$table = mosGetParam($_REQUEST, 'table');
$key = mosGetParam($_REQUEST, 'key', 'id');
$label = mosGetParam($_REQUEST, 'label', 'label');
$foreignKey = mosGetParam($_REQUEST, 'foreignkey', 'country_id');
$val = mosGetParam($_REQUEST, 'val', '1');

//run a query on the database to get the matching fields
$sql = "SELECT $key AS value, $label AS label FROM $table WHERE $foreignKey = '$val'";
$database->setQuery($sql);
$rows = $database->loadObjectList();

//write the results of the query back to the browser - the javascript code will then assign
//the text to the second drop down
foreach($rows as $row){
echo "<option value=\"$row->value\">$row->label</option>";
}
}
}