File modules/template_engine/components/html/component_checkbox/CheckboxComponent.class.php

Last commit: Thu Mar 10 13:09:06 2022 +0100	dankert	New: Remember some user inputs in the browser local storage.
1 <?php 2 3 namespace template_engine\components\html\component_checkbox; 4 5 use template_engine\components\html\Component; 6 use template_engine\element\CMSElement; 7 use template_engine\element\PHPBlockElement; 8 use template_engine\element\Value; 9 use template_engine\element\ValueExpression; 10 11 class CheckboxComponent extends Component 12 { 13 14 public $default = false; 15 public $name; 16 public $readonly = false; 17 public $required = false; 18 public $remember = false; 19 public $label; 20 21 public function createElement() 22 { 23 $checkbox = (new CMSElement('input')) 24 ->addAttribute('type','checkbox') 25 ->addStyleClass('form-checkbox'); 26 27 if ( $this->remember ) 28 $checkbox->addStyleClass('remember'); 29 30 if ( !$this->label ) 31 $checkbox->addAttribute('name',$this->name); 32 else 33 $checkbox->addAttribute('data-name',$this->name); 34 35 if ( $this->readonly ) 36 $checkbox->addAttribute('disabled','disabled'); 37 $checkbox->addAttribute('value','1'); 38 39 if ( $this->default ) 40 $condition = ''.PHPBlockElement::value($this->default); 41 else 42 $condition = '@$'.PHPBlockElement::value($this->name); 43 $checkbox->addConditionalAttribute('checked', $condition, 'checked'); 44 45 if ( $this->required ) 46 $checkbox->addAttribute( 'required','required'); 47 48 if ( $this->readonly && $this->required ) { 49 $hidden = (new CMSElement('input'))->addAttribute('type','hidden')->addAttribute('name',$this->name)->addAttribute('value','1'); 50 $checkbox->addChild( $hidden ); 51 } 52 53 if ( $this->label ) { 54 $label = (new CMSElement('label')) 55 //->addStyleClass('form-checkbox') 56 ->addChild($checkbox) 57 ->addChild( (new CMSElement('input'))->addAttribute('type','hidden')->addAttribute('name',$this->name)->addConditionalAttribute('value', $condition, '1') ) 58 ->addChild( (new CMSElement('span')) 59 ->addStyleClass('form-label') 60 ->content($this->label)); 61 return $label; 62 } 63 64 return $checkbox; 65 } 66 }
Download modules/template_engine/components/html/component_checkbox/CheckboxComponent.class.php
History Thu, 10 Mar 2022 13:09:06 +0100 dankert New: Remember some user inputs in the browser local storage. Wed, 9 Mar 2022 13:28:52 +0100 dankert Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()' Sun, 18 Oct 2020 01:30:49 +0200 Jan Dankert New component "fieldset" for better form layout. Wed, 14 Oct 2020 22:36:29 +0200 Jan Dankert Refactoring: Fixed the namespace in component classes, now the are able to be load by the standard autoloader. Wed, 14 Oct 2020 22:20:22 +0200 Jan Dankert Refactoring: Renamed component folders, because 'if' is no valid namespace fragment.