Changeset 748

Show
Ignore:
Timestamp:
08/28/08 14:09:27 (3 months ago)
Author:
camper
Message:

Forms fields: denyEnter call removed from defaults, Form::denyEnter() should be called explicitly to prevent submission by Enter

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/Form.php

    r733 r748  
    112112        return $this; 
    113113    } 
     114    function denyEnter(){ 
     115        // prevents the submit on Enter for the last field 
     116        // apply it when there is only one field on the form 
     117        $this->last_field->denyEnter(); 
     118        return $this; 
     119    } 
    114120        function setFieldComment($comment){ 
    115121                /** 
    116                  * Adds a comment to the last field.  
     122                 * Adds a comment to the last field. 
    117123                 * Comment will be inserted to the field_comment tag of the form template 
    118124                 */ 
     
    195201        } 
    196202        //if($this->elements[$field_or_array] instanceof Form_Button)echo caller_lookup(0); 
    197         if($this->elements[$field_or_array] instanceof Form_Field)  
     203        if($this->elements[$field_or_array] instanceof Form_Field) 
    198204                $this->elements[$field_or_array]->set($value); 
    199205        else{ 
     
    239245                    ($msg?$msg:'".$this->caption." is a mandatory field!').'");'); 
    240246               return $this; 
    241     }   
    242          
    243          
     247    } 
     248 
     249 
    244250    function setNotNull($msg=''){ 
    245251        $this->validateNotNULL($msg); 
     
    268274            ->setLabel($label) 
    269275            ->setNoSave(); 
    270         if (!is_null($color))    
     276        if (!is_null($color)) 
    271277                $this->last_field->setColor($color); 
    272278 
     
    285291        $field = $this->last_button = $this->add('Form_Button',isset($name)?$name:$label,'form_buttons') 
    286292            ->setLabel($label); 
    287              
    288         if (!is_null($color))    
     293 
     294        if (!is_null($color)) 
    289295                $field->setColor($color); 
    290                    
     296 
    291297        $field->setNoSave(); 
    292298 
     
    344350 
    345351 
    346          
     352 
    347353    function submitted(){ 
    348354        /** 
  • trunk/lib/Form/Field.php

    r744 r748  
    127127                                /* Since all browsers except Opera handle only button cancelling on even onKeyDown and Opera on KeyPress 
    128128                                   Determine whats the browser and put JS in proper event  */ 
    129                                 (stripos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ? 'onKeyPress' : 'onKeyDown') =>(is_null($this->onkeypress)?'return denyEnter(event);':$this->onkeypress->getString()), 
     129                                (stripos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false ? 'onKeyPress' : 'onKeyDown') =>(is_null($this->onkeypress)?'':$this->onkeypress->getString()), 
    130130                                'onfocus'=>(is_null($this->onfocus)?'':$this->onfocus->getString()), 
    131131                                'onblur'=>(is_null($this->onblur)?'':$this->onblur->getString()), 
     
    133133                        ),$attr,$this->attr) 
    134134                ); 
     135    } 
     136    function denyEnter(){ 
     137        $this->onKeyPress()->ajaxFunc('if(isKeyPressed(e, kReturn))return false'); 
     138        return $this; 
    135139    } 
    136140    function setSeparator($separator){ 
     
    419423        $this->value_list = $list; 
    420424    } 
    421     function loadPOST(){  
     425    function loadPOST(){ 
    422426        $data=$_POST[$this->name]; 
    423427        if(is_array($data))$data=join(',',$data); 
     
    441445        return parent::validate(); 
    442446    } 
    443     function getInput($attr=array()){  
     447    function getInput($attr=array()){ 
    444448        $output=$this->getTag('select',array_merge(array( 
    445449                        'name'=>$this->name, 
     
    460464                        )) 
    461465                    .htmlspecialchars($descr) 
    462                     .$this->getTag('/option');  
     466                    .$this->getTag('/option'); 
    463467            } else { 
    464468                $output.= 
     
    468472                        )) 
    469473                    .htmlspecialchars($descr) 
    470                     .$this->getTag('/option');               
     474                    .$this->getTag('/option'); 
    471475            } 
    472476        } 
  • trunk/lib/QuickSearch.php

    r732 r748  
    1515        $this->useDQ($this->owner->dq); 
    1616        //on field change we should change a name of a button also: 'clear' in the name will clear fields 
    17         $this->addField('Search','q','Find')->onChange()->ajaxFunc($this->setGoFunc()); 
     17        $this->addField('Search','q','Find')->denyEnter()->onChange()->ajaxFunc($this->setGoFunc()); 
    1818        $this->last_field->onKeyPress()->ajaxFunc($this->setGoFunc()); 
    1919        $this->addButton('Clear','Clear')->submitForm($this);