File modules/template_engine/components/html/component_radio/RadioComponent.class.php

Last commit: Sun Oct 18 01:30:49 2020 +0200	Jan Dankert	New component "fieldset" for better form layout.
1 <?php 2 3 namespace template_engine\components\html\component_radio; 4 5 use template_engine\components\html\FieldComponent; 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 RadioComponent extends FieldComponent 12 { 13 14 // Bisher nicht in Benutzung. 15 public $readonly = false; 16 17 public $value; 18 19 public $prefix=''; 20 21 public $suffix=''; 22 23 public $class = ''; 24 25 public $onchange; 26 27 public $children; 28 29 public $checked; 30 31 public $label = ''; 32 33 34 35 public function createElement() 36 { 37 38 $radio = (new CMSElement('input')) 39 ->addAttribute('type','radio') 40 ->addStyleClass('form-radio'); 41 42 43 $radio->addAttribute('name',$this->name); 44 if ($this->readonly) 45 $radio->addAttribute('disabled','disabled'); 46 $radio->addAttribute('value',$this->value); 47 48 $condition = '@$'.PHPBlockElement::value($this->name).'==\''.$this->value.'\''; 49 $radio->addConditionalAttribute('checked', $condition, 'checked'); 50 51 //$radio->addAttribute('checked',Value::createExpression(ValueExpression::TYPE_DATA_VAR,$this->name)); 52 53 if ( $this->readonly && $this->required ) { 54 $hidden = (new CMSElement('input'))->addAttribute('type','hidden')->addAttribute('name',$this->name)->addAttribute('value','1'); 55 $radio->addChild( $hidden ); 56 } 57 58 if ( $this->class ) 59 $radio->addStyleClass($this->class); 60 61 if ( $this->label ) { 62 $label = (new CMSElement('label')) 63 ->addChild( $radio ) 64 ->addChild( (new CMSElement('span')) 65 ->addStyleClass('form-label') 66 ->content($this->label)); 67 return $label; 68 } 69 70 return $radio; 71 } 72 }
Download modules/template_engine/components/html/component_radio/RadioComponent.class.php
History 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.