- 1
[Opened] How to pass javascript variables to a zone ?
Posted by pheromix on 04/01/2016 10:48
When the page loads :
class defaultCtrl extends jController { /** * */ function index() { jClasses::inc("commun~toolsSrv") ; $oResp = $this->getResponse('html'); $oResp->bodyTpl = "utilisateurs~FoHome" ; $zUrlGetZone = jUrl::get("commun~default:getZone") ; // list of profiles $toProfils = toolsSrv::getAllProfils() ; $oResp->body->assignZone('oZoneListe', 'utilisateurs~FoListeUtilisateurs', array()) ; // this will be for a dataTable-like zone $oResp->body->assign("zUrlGetZone", $zUrlGetZone) ; $oResp->body->assign("toProfils", $toProfils) ; // this will feed a listbox #selectProfil return $oResp; }
The template :
<select name="selectProfil" id="selectProfil"> <option value="0">--- Tous ---</option> {foreach $toProfils as $oProfil} <option value="{$oProfil->id_profil}">{$oProfil->lib_profil}</option> {/foreach} </select> <br /> <div class="ajaxZone"> {$oZoneListe} </div>
Code of commun~default:getZone :
function getZone() { $oResp = $this->getResponse('text'); $zZone = $this->param('zone'); if (is_null($zZone)) { throw new Exception('ParamĂȘtre zone requis'); } $tParams = $GLOBALS['gJCoord']->request->params; $oResp->content = jZone::get($zZone, $tParams); return $oResp; }
When the #selectProfil listbox changes then I want to filter the results displayed on the zone oZoneListe :
{literal} <script type="text/javascript"> $(function() { $("#selectProfil").change( function() { var iProfilId = $(this).val() ; var zSrc = '{/literal}{$zUrlGetZone}{literal}' ; var zone = 'utilisateurs~FoListeUtilisateurs' ; $(".ajaxZone").load(zSrc, {zone:zone, iProfilId:iProfilId}) ; } ) ; }) ; </script>
So I want to filter the zone when the listbox changes. The problem is that I cannot get the parameter iProfilId inside the zone ! So how to pass this javascript variable to the zone ?
- 1