All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
  Print view

how to ajax refresh atklistattribute or atkmultiselect
Author Message
PostPosted: Thu Nov 17, 2016 11:04 am 
Regular
User avatar
Offline

Joined: Thu Aug 25, 2011 9:31 pm
Posts: 308
Location: Mumbai, India
how to ajax refresh atklistattribute or atkmultiselect ?

i have atklistattribute or atkmultiselect attributes which are based on code/description arrays and these arrays are populated based on a query which involves a query based on value of a user selected column.

Say AtkList of Designations shown depend on the division selected by the user.

Then how to Ajax/Refresh ie AddDependee/Dependency refresh the atklist

Loose code / prototype is given belwo - it is NOT working - just to clarify what i wish to do


Code:
:
      $division = &$this->add(new atkListAttribute("division",$divn_nm,$divn_cd,AF_HIDE_LIST|AF_OBLIGATORY));
      $division->addDependency(array($this, "divnDependency"));


       global  $desg_cd;
       global  $desg_nm;

       $designrow = $db->getrows("SELECT DISTINCT designation FROM organogram ");
       for ($qcnt=0; $qcnt < count($designrow); $qcnt++)
{
          $desg_cd[$qcnt] = $designrow[$qcnt]['designation'];
          $desg_nm[$qcnt] = $designrow[$qcnt]['designation'];     
}


      $this->add(new atkMultiSelectAttribute("designation",$desg_cd,$desg_nm,5,AF_CHECK_ALL|AF_LINKS_BOTTOM|AF_HIDE_LIST);
:


 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
    function divnDependency(atkEditFormModifier $modifier)
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
    {
      $record = &$modifier->getRecord();
      if ($modifier->isInitial())  return;

       global  $desg_cd;
       global  $desg_nm;

       $db = &atkGetDb();
       $designrow = $db->getrows("SELECT DISTINCT designation FROM organogram where divn = '" . $record['division'] . "'");
       for ($qcnt=0; $qcnt < count($designrow); $qcnt++)
       {
          $desg_cd[$qcnt] = $designrow[$qcnt]['designation'];
          $desg_nm[$qcnt] = $designrow[$qcnt]['designation'];     
}
      $modifier->refreshAttribute('designation');

     }     //function divnDependency()


Top
 Profile  
 

Re: how to ajax refresh atklistattribute or atkmultiselect
PostPosted: Thu Nov 17, 2016 11:27 am 
Regular
User avatar
Offline

Joined: Thu Aug 25, 2011 9:31 pm
Posts: 308
Location: Mumbai, India
ok seems to have got it

atkmultiselect inherits atklistattribute which has following method to set revised arrays

function setOptions($optionArray, $valueArray)

so my working revised code looks like

Code:

:
      $division = &$this->add(new atkListAttribute("division",$divn_nm,$divn_cd,AF_HIDE_LIST|AF_OBLIGATORY));
      $division->addDependency(array($this, "divnDependency"));

       //global NOT required  commented
       //global  $desg_cd;
       //global  $desg_nm;

       $designrow = $db->getrows("SELECT DISTINCT designation FROM organogram ");
       for ($qcnt=0; $qcnt < count($designrow); $qcnt++)
{
          $desg_cd[$qcnt] = $designrow[$qcnt]['designation'];
          $desg_nm[$qcnt] = $designrow[$qcnt]['designation'];     
}


      $this->add(new atkMultiSelectAttribute("designation",$desg_cd,$desg_nm,5,AF_CHECK_ALL|AF_LINKS_BOTTOM|AF_HIDE_LIST);
:



   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
    function divnDependency(atkEditFormModifier $modifier)
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
    {
      $record = &$modifier->getRecord();
      if ($modifier->isInitial())  return;

       //global  $desg_cd;
       //global  $desg_nm;

       $db = &atkGetDb();
       $designrow = $db->getrows("SELECT DISTINCT designation FROM organogram where divn = '" . $record['division'] . "'");

       for ($qcnt=0; $qcnt < count($designrow); $qcnt++)
{
          $desg_cd[$qcnt] = $designrow[$qcnt]['designation'];
          $desg_nm[$qcnt] = $designrow[$qcnt]['designation'];   
             }


    //function setOptions($optionArray, $valueArray)
    //$l_date = $this->getAttribute('l_date')->value2db($record); //yyyy-mm-dd
    $designation = $this->getAttribute('designation')->setOptions($desg_nm,$desg_cd);


      $modifier->refreshAttribute('designation');

     }     //function hqDependency()






Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group