Changeset 910

Show
Ignore:
Timestamp:
04/28/08 15:51:17 (3 months ago)
Author:
laurentj
Message:

jforms-group: work in progress

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php

    r906 r910  
    4343 
    4444    /** 
     45     * List of top controls 
     46     * array of jFormsControl objects 
     47     * @var array 
     48     * @see jFormsControl 
     49     */ 
     50    protected $_topControls = array(); 
     51 
     52    /** 
    4553     * List of submit buttons 
    4654     * array of jFormsControl objects 
     
    8694     * @var jFormsDataContainer 
    8795     */ 
    88     protected $_container=null; 
    89  
    90     /** 
    91      * says if the form is readonly 
    92      * @var boolean 
    93      */ 
    94     protected $_readOnly = false; 
     96    protected $_container = null; 
    9597 
    9698    /** 
     
    102104    /** 
    103105     * list of modified controls 
    104      * @var array 
     106     * keys are name of control, value is the old value of the control 
     107     * @var array  
    105108     */ 
    106109    protected $_modifiedControls = array(); 
     
    131134        $req = $GLOBALS['gJCoord']->request; 
    132135        $this->_modifiedControls=array(); 
    133         foreach($this->_controls as $name=>$ctrl){ 
    134             if(!$this->_container->isActivated($name)
     136        foreach($this->_topControls as $name=>$ctrl){ 
     137            if(!$this->_container->isActivated($name) || $this->_container->isReadonly($name)
    135138                continue; 
    136             $value = $req->getParam($name); 
    137  
    138             //@todo à prevoir un meilleur test, pour les formulaires sur plusieurs pages 
    139             if($value === null) $value=''; 
    140  
    141             $value = $ctrl->getValueFromRequest($this, $value); 
    142  
    143             if($this->_container->data[$name] != $value) 
    144                 $this->_modifiedControls[$name] = $this->_container->data[$name]; 
    145             $this->_container->data[$name] = $value; 
     139            $this->setData($name, $ctrl->getValueFromRequest($this, $req), true); 
    146140        } 
    147141    } 
     
    403397 
    404398    /** 
    405      * set the form  read only or read/write 
    406      * @param boolean $r true if you want read only 
    407      */ 
    408     public function setReadOnly($r = true){  $this->_readOnly = $r;  } 
    409  
    410     /** 
    411399     * return list of errors found during the check 
    412400     * @return array 
     
    429417     * @param string $value the data value 
    430418     */ 
    431     public function setData($name,$value){ 
     419    public function setData($name, $value, $registerInModified = false){ 
    432420        if($this->_controls[$name]->type == 'checkbox') { 
    433421            if($value != $this->_controls[$name]->valueOnCheck){ 
     
    438426            } 
    439427        } 
     428        if($registerInModified && $this->_container->data[$name] != $value) 
     429            $this->_modifiedControls[$name] = $this->_container->data[$name]; 
    440430        $this->_container->data[$name]=$value; 
    441431    } 
     
    473463     */ 
    474464    public function deactivate($name, $deactivation=true) { 
    475         if($deactivation) { 
    476             $this->_container->deactivate($name); 
    477         } 
    478         else { 
    479             $this->_container->deactivate($name, false); 
    480         } 
     465        $this->_container->deactivate($name, $deactivation); 
    481466    } 
    482467 
     
    489474        return $this->_container->isActivated($name); 
    490475    } 
     476 
     477 
     478    /** 
     479     * set a control readonly or not 
     480     * @param boolean $r true if you want read only 
     481     */ 
     482    public function setReadOnly($name, $r = true) { 
     483        $this->_container->setReadOnly($name, $r); 
     484    } 
     485 
     486    /** 
     487     * check if a control is readonly 
     488     * @return boolean true if it is readonly 
     489     */ 
     490    public function isReadOnly($name) { 
     491        return $this->_container->isReadOnly($name); 
     492    } 
     493 
    491494 
    492495    /** 
     
    625628    } 
    626629 
    627  
    628630    /** 
    629631    * add a control to the form 
     
    631633    */ 
    632634    protected function addControl($control){ 
     635        if(!$subcontrol) { 
     636            $this->_topControls [$control->ref] = $control; 
     637        } 
     638        $this->addChildControl($control); 
     639 
     640        if($control instanceof jFormsControlGroups) { 
     641            foreach($control->getChildControls() as $ctrl) 
     642                $this->addChildControl($ctrl); 
     643        } 
     644    } 
     645 
     646    /** 
     647    * add a control to the form 
     648    * @param $control jFormsControl 
     649    */ 
     650    protected function addChildControl($control){ 
    633651        $this->_controls [$control->ref] = $control; 
    634652        if($control->type =='submit') 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php

    r906 r910  
    4343 
    4444    /** 
     45     * List of top controls 
     46     * array of jFormsControl objects 
     47     * @var array 
     48     * @see jFormsControl 
     49     */ 
     50    protected $_topControls = array(); 
     51 
     52    /** 
    4553     * List of submit buttons 
    4654     * array of jFormsControl objects 
     
    8694     * @var jFormsDataContainer 
    8795     */ 
    88     protected $_container=null; 
    89  
    90     /** 
    91      * says if the form is readonly 
    92      * @var boolean 
    93      */ 
    94     protected $_readOnly = false; 
     96    protected $_container = null; 
    9597 
    9698    /** 
     
    102104    /** 
    103105     * list of modified controls 
    104      * @var array 
     106     * keys are name of control, value is the old value of the control 
     107     * @var array  
    105108     */ 
    106109    protected $_modifiedControls = array(); 
     
    131134        $req = $GLOBALS['gJCoord']->request; 
    132135        $this->_modifiedControls=array(); 
    133         foreach($this->_controls as $name=>$ctrl){ 
    134             if(!$this->_container->isActivated($name)
     136        foreach($this->_topControls as $name=>$ctrl){ 
     137            if(!$this->_container->isActivated($name) || $this->_container->isReadonly($name)
    135138                continue; 
    136             $value = $req->getParam($name); 
    137  
    138             //@todo à prevoir un meilleur test, pour les formulaires sur plusieurs pages 
    139             if($value === null) $value=''; 
    140  
    141             $value = $ctrl->getValueFromRequest($this, $value); 
    142  
    143             if($this->_container->data[$name] != $value) 
    144                 $this->_modifiedControls[$name] = $this->_container->data[$name]; 
    145             $this->_container->data[$name] = $value; 
     139            $this->setData($name, $ctrl->getValueFromRequest($this, $req), true); 
    146140        } 
    147141    } 
     
    403397 
    404398    /** 
    405      * set the form  read only or read/write 
    406      * @param boolean $r true if you want read only 
    407      */ 
    408     public function setReadOnly($r = true){  $this->_readOnly = $r;  } 
    409  
    410     /** 
    411399     * return list of errors found during the check 
    412400     * @return array 
     
    429417     * @param string $value the data value 
    430418     */ 
    431     public function setData($name,$value){ 
     419    public function setData($name, $value, $registerInModified = false){ 
    432420        if($this->_controls[$name]->type == 'checkbox') { 
    433421            if($value != $this->_controls[$name]->valueOnCheck){ 
     
    438426            } 
    439427        } 
     428        if($registerInModified && $this->_container->data[$name] != $value) 
     429            $this->_modifiedControls[$name] = $this->_container->data[$name]; 
    440430        $this->_container->data[$name]=$value; 
    441431    } 
     
    473463     */ 
    474464    public function deactivate($name, $deactivation=true) { 
    475         if($deactivation) { 
    476             $this->_container->deactivate($name); 
    477         } 
    478         else { 
    479             $this->_container->deactivate($name, false); 
    480         } 
     465        $this->_container->deactivate($name, $deactivation); 
    481466    } 
    482467 
     
    489474        return $this->_container->isActivated($name); 
    490475    } 
     476 
     477 
     478    /** 
     479     * set a control readonly or not 
     480     * @param boolean $r true if you want read only 
     481     */ 
     482    public function setReadOnly($name, $r = true) { 
     483        $this->_container->setReadOnly($name, $r); 
     484    } 
     485 
     486    /** 
     487     * check if a control is readonly 
     488     * @return boolean true if it is readonly 
     489     */ 
     490    public function isReadOnly($name) { 
     491        return $this->_container->isReadOnly($name); 
     492    } 
     493 
    491494 
    492495    /** 
     
    625628    } 
    626629 
    627  
    628630    /** 
    629631    * add a control to the form 
     
    631633    */ 
    632634    protected function addControl($control){ 
     635        if(!$subcontrol) { 
     636            $this->_topControls [$control->ref] = $control; 
     637        } 
     638        $this->addChildControl($control); 
     639 
     640        if($control instanceof jFormsControlGroups) { 
     641            foreach($control->getChildControls() as $ctrl) 
     642                $this->addChildControl($ctrl); 
     643        } 
     644    } 
     645 
     646    /** 
     647    * add a control to the form 
     648    * @param $control jFormsControl 
     649    */ 
     650    protected function addChildControl($control){ 
    633651        $this->_controls [$control->ref] = $control; 
    634652        if($control->type =='submit') 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php

    r906 r910  
    4343 
    4444    /** 
     45     * List of top controls 
     46     * array of jFormsControl objects 
     47     * @var array 
     48     * @see jFormsControl 
     49     */ 
     50    protected $_topControls = array(); 
     51 
     52    /** 
    4553     * List of submit buttons 
    4654     * array of jFormsControl objects 
     
    8694     * @var jFormsDataContainer 
    8795     */ 
    88     protected $_container=null; 
    89  
    90     /** 
    91      * says if the form is readonly 
    92      * @var boolean 
    93      */ 
    94     protected $_readOnly = false; 
     96    protected $_container = null; 
    9597 
    9698    /** 
     
    102104    /** 
    103105     * list of modified controls 
    104      * @var array 
     106     * keys are name of control, value is the old value of the control 
     107     * @var array  
    105108     */ 
    106109    protected $_modifiedControls = array(); 
     
    131134        $req = $GLOBALS['gJCoord']->request; 
    132135        $this->_modifiedControls=array(); 
    133         foreach($this->_controls as $name=>$ctrl){ 
    134             if(!$this->_container->isActivated($name)
     136        foreach($this->_topControls as $name=>$ctrl){ 
     137            if(!$this->_container->isActivated($name) || $this->_container->isReadonly($name)
    135138                continue; 
    136             $value = $req->getParam($name); 
    137  
    138             //@todo à prevoir un meilleur test, pour les formulaires sur plusieurs pages 
    139             if($value === null) $value=''; 
    140  
    141             $value = $ctrl->getValueFromRequest($this, $value); 
    142  
    143             if($this->_container->data[$name] != $value) 
    144                 $this->_modifiedControls[$name] = $this->_container->data[$name]; 
    145             $this->_container->data[$name] = $value; 
     139            $this->setData($name, $ctrl->getValueFromRequest($this, $req), true); 
    146140        } 
    147141    } 
     
    403397 
    404398    /** 
    405      * set the form  read only or read/write 
    406      * @param boolean $r true if you want read only 
    407      */ 
    408     public function setReadOnly($r = true){  $this->_readOnly = $r;  } 
    409  
    410     /** 
    411399     * return list of errors found during the check 
    412400     * @return array 
     
    429417     * @param string $value the data value 
    430418     */ 
    431     public function setData($name,$value){ 
     419    public function setData($name, $value, $registerInModified = false){ 
    432420        if($this->_controls[$name]->type == 'checkbox') { 
    433421            if($value != $this->_controls[$name]->valueOnCheck){ 
     
    438426            } 
    439427        } 
     428        if($registerInModified && $this->_container->data[$name] != $value) 
     429            $this->_modifiedControls[$name] = $this->_container->data[$name]; 
    440430        $this->_container->data[$name]=$value; 
    441431    } 
     
    473463     */ 
    474464    public function deactivate($name, $deactivation=true) { 
    475         if($deactivation) { 
    476             $this->_container->deactivate($name); 
    477         } 
    478         else { 
    479             $this->_container->deactivate($name, false); 
    480         } 
     465        $this->_container->deactivate($name, $deactivation); 
    481466    } 
    482467 
     
    489474        return $this->_container->isActivated($name); 
    490475    } 
     476 
     477 
     478    /** 
     479     * set a control readonly or not 
     480     * @param boolean $r true if you want read only 
     481     */ 
     482    public function setReadOnly($name, $r = true) { 
     483        $this->_container->setReadOnly($name, $r); 
     484    } 
     485 
     486    /** 
     487     * check if a control is readonly 
     488     * @return boolean true if it is readonly 
     489     */ 
     490    public function isReadOnly($name) { 
     491        return $this->_container->isReadOnly($name); 
     492    } 
     493 
    491494 
    492495    /** 
     
    625628    } 
    626629 
    627  
    628630    /** 
    629631    * add a control to the form 
     
    631633    */ 
    632634    protected function addControl($control){ 
     635        if(!$subcontrol) { 
     636            $this->_topControls [$control->ref] = $control; 
     637        } 
     638        $this->addChildControl($control); 
     639 
     640        if($control instanceof jFormsControlGroups) { 
     641            foreach($control->getChildControls() as $ctrl) 
     642                $this->addChildControl($ctrl); 
     643        } 
     644    } 
     645 
     646    /** 
     647    * add a control to the form 
     648    * @param $control jFormsControl 
     649    */ 
     650    protected function addChildControl($control){ 
    633651        $this->_controls [$control->ref] = $control; 
    634652        if($control->type =='submit') 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsBase.class.php

    r906 r910  
    4343 
    4444    /** 
     45     * List of top controls 
     46     * array of jFormsControl objects 
     47     * @var array 
     48     * @see jFormsControl 
     49     */ 
     50    protected $_topControls = array(); 
     51 
     52    /** 
    4553     * List of submit buttons 
    4654     * array of jFormsControl objects 
     
    8694     * @var jFormsDataContainer 
    8795     */ 
    88     protected $_container=null; 
    89  
    90     /** 
    91      * says if the form is readonly 
    92      * @var boolean 
    93      */ 
    94     protected $_readOnly = false; 
     96    protected $_container = null; 
    9597 
    9698    /** 
     
    102104    /** 
    103105     * list of modified controls 
    104      * @var array 
     106     * keys are name of control, value is the old value of the control 
     107     * @var array  
    105108     */ 
    106109    protected $_modifiedControls = array(); 
     
    131134        $req = $GLOBALS['gJCoord']->request; 
    132135        $this->_modifiedControls=array(); 
    133         foreach($this->_controls as $name=>$ctrl){ 
    134             if(!$this->_container->isActivated($name)
     136        foreach($this->_topControls as $name=>$ctrl){ 
     137            if(!$this->_container->isActivated($name) || $this->_container->isReadonly($name)
    135138                continue; 
    136             $value = $req->getParam($name); 
    137  
    138             //@todo à prevoir un meilleur test, pour les formulaires sur plusieurs pages 
    139             if($value === null) $value=''; 
    140  
    141             $value = $ctrl->getValueFromRequest($this, $value); 
    142  
    143             if($this->_container->data[$name] != $value) 
    144                 $this->_modifiedControls[$name] = $this->_container->data[$name]; 
    145             $this->_container->data[$name] = $value; 
     139            $this->setData($name, $ctrl->getValueFromRequest($this, $req), true); 
    146140        } 
    147141    } 
     
    403397 
    404398    /** 
    405      * set the form  read only or read/write 
    406      * @param boolean $r true if you want read only 
    407      */ 
    408     public function setReadOnly($r = true){  $this->_readOnly = $r;  } 
    409  
    410     /** 
    411399     * return list of errors found during the check 
    412400     * @return array 
     
    429417     * @param string $value the data value 
    430418     */ 
    431     public function setData($name,$value){ 
     419    public function setData($name, $value, $registerInModified = false){ 
    432420        if($this->_controls[$name]->type == 'checkbox') { 
    433421            if($value != $this->_controls[$name]->valueOnCheck){ 
     
    438426            } 
    439427        } 
     428        if($registerInModified && $this->_container->data[$name] != $value) 
     429            $this->_modifiedControls[$name] = $this->_container->data[$name]; 
    440430        $this->_container->data[$name]=$value; 
    441431    } 
     
    473463     */ 
    474464    public function deactivate($name, $deactivation=true) { 
    475         if($deactivation) { 
    476             $this->_container->deactivate($name); 
    477         } 
    478         else { 
    479             $this->_container->deactivate($name, false); 
    480         } 
     465        $this->_container->deactivate($name, $deactivation); 
    481466    } 
    482467 
     
    489474        return $this->_container->isActivated($name); 
    490475    } 
     476 
     477 
     478    /** 
     479     * set a control readonly or not 
     480     * @param boolean $r true if you want read only 
     481     */ 
     482    public function setReadOnly($name, $r = true) { 
     483        $this->_container->setReadOnly($name, $r); 
     484    } 
     485 
     486    /** 
     487     * check if a control is readonly 
     488     * @return boolean true if it is readonly 
     489     */ 
     490    public function isReadOnly($name) { 
     491        return $this->_container->isReadOnly($name); 
     492    } 
     493 
    491494 
    492495    /** 
     
    625628    } 
    626629 
    627  
    628630    /** 
    629631    * add a control to the form 
     
    631633    */ 
    632634    protected function addControl($control){ 
     635        if(!$subcontrol) { 
     636            $this->_topControls [$control->ref] = $control; 
     637        } 
     638        $this->addChildControl($control); 
     639 
     640        if($control instanceof jFormsControlGroups) { 
     641            foreach($control->getChildControls() as $ctrl) 
     642                $this->addChildControl($ctrl); 
     643        } 
     644    } 
     645 
     646    /** 
     647    * add a control to the form 
     648    * @param $control jFormsControl 
     649    */ 
     650    protected function addChildControl($control){ 
    633651        $this->_controls [$control->ref] = $control; 
    634652        if($control->type =='submit') 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsCompiler_jf_1_0.class.php

    r907 r910  
    299299        if(isset($attributes['readonly'])){ 
    300300            if('true' == $attributes['readonly']) 
    301                 $source[]='$ctrl->readonly=true;'; 
     301                $source[]='$form->setReadonly($ctrl->ref,true);'; 
    302302            unset($attributes['readonly']); 
    303303        } 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsCompiler_jf_1_0.class.php

    r907 r910  
    299299        if(isset($attributes['readonly'])){ 
    300300            if('true' == $attributes['readonly']) 
    301                 $source[]='$ctrl->readonly=true;'; 
     301                $source[]='$form->setReadonly($ctrl->ref,true);'; 
    302302            unset($attributes['readonly']); 
    303303        } 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsCompiler_jf_1_0.class.php

    r907 r910  
    299299        if(isset($attributes['readonly'])){ 
    300300            if('true' == $attributes['readonly']) 
    301                 $source[]='$ctrl->readonly=true;'; 
     301                $source[]='$form->setReadonly($ctrl->ref,true);'; 
    302302            unset($attributes['readonly']); 
    303303        } 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsCompiler_jf_1_0.class.php

    r907 r910  
    299299        if(isset($attributes['readonly'])){ 
    300300            if('true' == $attributes['readonly']) 
    301                 $source[]='$ctrl->readonly=true;'; 
     301                $source[]='$form->setReadonly($ctrl->ref,true);'; 
    302302            unset($attributes['readonly']); 
    303303        } 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php

    r906 r910  
    3434    } 
    3535 
     36    /** 
     37     * says if the control can have multiple values 
     38     */ 
    3639    function isContainer(){ 
    3740        return false; 
     
    5558    } 
    5659 
    57     function getValueFromRequest($form, $requestValue) { 
    58         return $requestValue
     60    function getValueFromRequest($form, $request) { 
     61        return $request->getParam($this->ref,'')
    5962    } 
    6063 
     
    9396        return $value; 
    9497    } 
    95  
    96  
    9798} 
    9899 
     
    181182    } 
    182183 
    183     function getValueFromRequest($form, $requestValue) { 
    184         if($requestValue){ 
    185             return  $this->valueOnCheck; 
     184    function getValueFromRequest($form, $request) { 
     185        $value = $request->getParam($this->ref); 
     186        if($value){ 
     187            return $this->valueOnCheck; 
    186188        }else{ 
    187189            return $this->valueOnUncheck; 
     
    254256    } 
    255257 
    256     function getValueFromRequest($form, $requestValue) { 
     258    function getValueFromRequest($form, $request) { 
    257259        if(isset($_FILES[$this->ref])){ 
    258260            return $_FILES[$this->ref]['name']; 
     
    275277    } 
    276278 
    277     function getValueFromRequest($form, $requestValue) { 
    278  
    279         if($requestValue && !$this->standalone) { 
     279    function getValueFromRequest($form, $request) { 
     280 
     281        $value = $request->getParam($this->ref,''); 
     282 
     283        if($value && !$this->standalone) { 
    280284            // because IE send the <button> content as value instead of the content of the 
    281285            // "value" attribute, we should verify it and get the real value 
    282             // or when using <input type="submit">, we have only the label as value (in all browsers... 
     286            // or when using <input type="submit">, we have only the label as value (in all browsers...) 
    283287            $data = $this->datasource->getData($form); 
    284             if(!isset($data[$requestValue])) { 
     288            if(!isset($data[$value])) { 
    285289                $data=array_flip($data); 
    286                 if(isset($data[$requestValue])) { 
    287                     $requestValue = $data[$requestValue]; 
     290                if(isset($data[$value])) { 
     291                    $value = $data[$value]; 
    288292                } 
    289293            } 
    290294        } 
    291         return $requestValue; 
     295        return $value; 
    292296    } 
    293297 
     
    459463 
    460464 
     465/** 
     466 * abstract classes for controls which contain other controls 
     467 * @package     jelix 
     468 * @subpackage  forms 
     469 */ 
     470abstract class jFormsControlGroups extends jFormsControl { 
     471    public $type = 'groups'; 
     472 
     473    protected $childControls = array(); 
     474 
     475    function check($form){ 
     476        $check = parent::check($form); 
     477        $container = $form->getContainer(); 
     478        foreach($this->childControls as $name => $ctrl) { 
     479            $err = $ctrl->check($this); 
     480            if($err !== null) 
     481                $container->errors[$name]= $err; 
     482        } 
     483        return $check; 
     484    } 
     485 
     486    function getDisplayValue($value){ 
     487        return $value; 
     488    } 
     489 
     490    function getValueFromRequest($form, $request) { 
     491        $container = $form->getContainer(); 
     492        foreach($this->childControls as $name => $ctrl) { 
     493            if(!$container->isActivated($name) || $container->isReadonly($name)) continue; 
     494            $form->setData($name, $ctrl->getValueFromRequest($form, $request),true); 
     495        } 
     496        return $request->getParam($this->ref,''); 
     497    } 
     498 
     499    function prepareValueFromDao($value, $daoDatatype) { 
     500        return $value; 
     501    } 
     502 
     503    function addChildControl($control) { 
     504        $this->childControls[$control->ref]=$control; 
     505    } 
     506 
     507    function getChildControls() { return $this->childControls;} 
     508} 
     509 
     510/** 
     511 * choice 
     512 * @package     jelix 
     513 * @subpackage  forms 
     514 */ 
     515class jFormsControlGroup extends jFormsControlGroups { 
     516    public $type="group"; 
     517} 
     518 
     519 
     520 
     521/** 
     522 * choice 
     523 * @package     jelix 
     524 * @subpackage  forms 
     525 */ 
     526class jFormsControlChoice extends jFormsControlGroups { 
     527    public $type="choice"; 
     528} 
     529 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php

    r906 r910  
    3434    } 
    3535 
     36    /** 
     37     * says if the control can have multiple values 
     38     */ 
    3639    function isContainer(){ 
    3740        return false; 
     
    5558    } 
    5659 
    57     function getValueFromRequest($form, $requestValue) { 
    58         return $requestValue
     60    function getValueFromRequest($form, $request) { 
     61        return $request->getParam($this->ref,'')
    5962    } 
    6063 
     
    9396        return $value; 
    9497    } 
    95  
    96  
    9798} 
    9899 
     
    181182    } 
    182183 
    183     function getValueFromRequest($form, $requestValue) { 
    184         if($requestValue){ 
    185             return  $this->valueOnCheck; 
     184    function getValueFromRequest($form, $request) { 
     185        $value = $request->getParam($this->ref); 
     186        if($value){ 
     187            return $this->valueOnCheck; 
    186188        }else{ 
    187189            return $this->valueOnUncheck; 
     
    254256    } 
    255257 
    256     function getValueFromRequest($form, $requestValue) { 
     258    function getValueFromRequest($form, $request) { 
    257259        if(isset($_FILES[$this->ref])){ 
    258260            return $_FILES[$this->ref]['name']; 
     
    275277    } 
    276278 
    277     function getValueFromRequest($form, $requestValue) { 
    278  
    279         if($requestValue && !$this->standalone) { 
     279    function getValueFromRequest($form, $request) { 
     280 
     281        $value = $request->getParam($this->ref,''); 
     282 
     283        if($value && !$this->standalone) { 
    280284            // because IE send the <button> content as value instead of the content of the 
    281285            // "value" attribute, we should verify it and get the real value 
    282             // or when using <input type="submit">, we have only the label as value (in all browsers... 
     286            // or when using <input type="submit">, we have only the label as value (in all browsers...) 
    283287            $data = $this->datasource->getData($form); 
    284             if(!isset($data[$requestValue])) { 
     288            if(!isset($data[$value])) { 
    285289                $data=array_flip($data); 
    286                 if(isset($data[$requestValue])) { 
    287                     $requestValue = $data[$requestValue]; 
     290                if(isset($data[$value])) { 
     291                    $value = $data[$value]; 
    288292                } 
    289293            } 
    290294        } 
    291         return $requestValue; 
     295        return $value; 
    292296    } 
    293297 
     
    459463 
    460464 
     465/** 
     466 * abstract classes for controls which contain other controls 
     467 * @package     jelix 
     468 * @subpackage  forms 
     469 */ 
     470abstract class jFormsControlGroups extends jFormsControl { 
     471    public $type = 'groups'; 
     472 
     473    protected $childControls = array(); 
     474 
     475    function check($form){ 
     476        $check = parent::check($form); 
     477        $container = $form->getContainer(); 
     478        foreach($this->childControls as $name => $ctrl) { 
     479            $err = $ctrl->check($this); 
     480            if($err !== null) 
     481                $container->errors[$name]= $err; 
     482        } 
     483        return $check; 
     484    } 
     485 
     486    function getDisplayValue($value){ 
     487        return $value; 
     488    } 
     489 
     490    function getValueFromRequest($form, $request) { 
     491        $container = $form->getContainer(); 
     492        foreach($this->childControls as $name => $ctrl) { 
     493            if(!$container->isActivated($name) || $container->isReadonly($name)) continue; 
     494            $form->setData($name, $ctrl->getValueFromRequest($form, $request),true); 
     495        } 
     496        return $request->getParam($this->ref,''); 
     497    } 
     498 
     499    function prepareValueFromDao($value, $daoDatatype) { 
     500        return $value; 
     501    } 
     502 
     503    function addChildControl($control) { 
     504        $this->childControls[$control->ref]=$control; 
     505    } 
     506 
     507    function getChildControls() { return $this->childControls;} 
     508} 
     509 
     510/** 
     511 * choice 
     512 * @package     jelix 
     513 * @subpackage  forms 
     514 */ 
     515class jFormsControlGroup extends jFormsControlGroups { 
     516    public $type="group"; 
     517} 
     518 
     519 
     520 
     521/** 
     522 * choice 
     523 * @package     jelix 
     524 * @subpackage  forms 
     525 */ 
     526class jFormsControlChoice extends jFormsControlGroups { 
     527    public $type="choice"; 
     528} 
     529 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php

    r906 r910  
    3434    } 
    3535 
     36    /** 
     37     * says if the control can have multiple values 
     38     */&nb