Changeset 750

Show
Ignore:
Timestamp:
08/30/08 09:51:10 (3 months ago)
Author:
camper
Message:

CmdForm?: specific field validation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • addons/camper/CmdForm.php

    r696 r750  
    88        public $section_open=null;                      // template chunk that opens new section 
    99        public $section_close=null;                     // template chunk that closes section 
    10          
     10 
    1111        function init(){ 
    1212                // template->get 
     
    1515                $this->section_close=$this->template->is_set('section_close')?$this->template->cloneRegion('section_close'): 
    1616                $this->template->cloneRegion('form_comment');   // yes, this cloning should be twice in the order like it is 
    17                                                                                                                 // if you comment out one of them, you'll see  
     17                                                                                                                // if you comment out one of them, you'll see 
    1818                $this->template->tryDel('section_open'); 
    1919                $this->template->tryDel('section_close'); 
    20                  
     20 
    2121                parent::init(); 
    2222        } 
     
    2828                return $this; 
    2929        } 
    30          
     30 
    3131        function update(){ 
    3232                foreach($this->elements as $short_name=>$element){ 
    33                         if($element instanceof Form_Field &&  
     33                        if($element instanceof Form_Field && 
    3434                                ($element->get()===''||is_null($element->get()))) 
    3535                                $this->set($short_name,$element->default_value); 
     
    3737                return parent::update(); 
    3838        } 
    39          
     39 
    4040        function addField($type,$name,$caption=null,$attr=null){ 
    4141                // opening Section if there is no any 
     
    4848        function addComment($comment){ 
    4949                if(!$this->section_opened)$this->newSection(); 
    50                  
     50 
    5151                return parent::addComment($comment); 
    5252        } 
     
    5858                /* 
    5959                 * Opens column/row 
    60                  *  
     60                 * 
    6161                 */ 
    6262                if(!is_object($this->section_open))return $this; 
     
    100100        return $data; 
    101101    } 
     102        function validateField($condition,$msg='',$field=null){ 
     103                if(is_null($field))$field=$this->last_field; 
     104                if(!is_object($field))$field=$this->getElement($field); 
     105                $field->addHook('validate','if(!('.$condition.'))$this->displayFieldError("'. 
     106                        ($msg?$msg:'Error in ".$this->caption."').'");'); 
     107                return $this; 
     108        } 
    102109 
    103110    /*function addComment($comment){