Hello cooks
Nobody can help me ?
I do not understand why all the subcategories are displayed.
The combobox "subcategory" is not filtered by the first "category".
I could do it in raw, but I prefer to do it properly in the way proposed by Jcook
In the category view.html.php I have this :
protected function displayAjax($tpl = null)
{
$jinput = JFactory::getApplication()->input;
$render = $jinput->get('render', null, 'CMD');
$token = $jinput->get('token', null, 'BASE64');
$values = $jinput->get('values', null, 'ARRAY');
switch($render)
{
case 's_cat':
$model = $this->getModel();
$model->addSelect('a.nom');
$items = $model->getItems();
$selected = (is_array($values))?$values[count($values)-1]:$values;
$ajaxNamespace = "maintenance.souscategories.ajax.s_cat";
$wrapper = "_ajax_souscategories_$render";
$event = 'jQuery("#__ajx_sous_categorie").val("");'
. 'if(this.value != ""){'
. 'jQuery("#' . $wrapper . '").jdomAjax({namespace:"' . $ajaxNamespace . '", vars:{"filter_categorie":this.value}})'
. '}else{'
. 'jQuery("#' . $wrapper . '").innerHTML = "";'
. '}';
echo '<div class="ajaxchain-filter ajaxchain-filter-hz">';
echo JDom::_('html.form.input.select', array(
'dataKey' => '_sous_categorie_categorie',
'dataValue' => $selected,
'domClass' => 'validate[required]',
'labelKey' => 'nom',
'list' => $items,
'listKey' => 'id',
'nullLabel' => 'MAINTENANCE_FILTER_NULL_CATEGORIE',
'selectors' => array(
'onchange' => $event
)
));
echo '</div>';
//Ajax chain on load -> Follows the values
echo JDom::_('html.form.input.ajax.chain', array(
'ajaxWrapper' => $wrapper,
'ajaxContext' => $ajaxNamespace,
'ajaxVars' => array(
'filter_categorie' => $selected,
'values' => $values),
'ajaxToken' => $token,
));
//Wrapper Div
echo("<div id='" . $wrapper ."' class='ajaxchain-wrapper ajaxchain-wrapper-hz'></div>");
break;
}
exit();
}
Dans le second souscatégorie viws.html.php i have :
protected function displayAjax($tpl = null)
{
$jinput = JFactory::getApplication()->input;
$render = $jinput->get('render', null, 'CMD');
$token = $jinput->get('token', null, 'BASE64');
$values = $jinput->get('values', null, 'ARRAY');
switch($render)
{
case 's_cat':
/* Ajax Chain : Sous-Catégorie > Nom
* Called from: view:ticket, layout:modify
* Group Level : 0
*/
$model = $this->getModel();
$model->addSelect('a.nom');
$items = $model->getItems();
$selected = (is_array($values))?$values[count($values)-1]:$values;
$event = 'jQuery("#jform_sous_categorie").val(this.value);';
echo '<div class="ajaxchain-filter ajaxchain-filter-hz">';
echo '<div class="separator">';
echo JDom::_('html.form.input.select', array(
'dataKey' => '__ajx_sous_categorie',
'dataValue' => $selected,
'domClass' => 'validate[required]',
'labelKey' => 'nom',
'list' => $items,
'listKey' => 'id',
'nullLabel' => 'MAINTENANCE_FILTER_NULL_SOUSCATEGORIE',
'selectors' => array(
'onchange' => $event
)
));
echo '</div>';
echo '</div>';
break;
}
exit();
}
I think everything is correct, but I do not understand why it does not work.
thank you in advance
Nicolas