File modules/template_engine/components/html/component_input/InputComponent.class.php
Last commit: Tue Jan 14 01:57:22 2025 +0100 Jan Dankert New: Some new template element types like 'url','email','range','password','date','time', ...; New: datalists for input fields; Refactoring: Cleaner templates and actions for editing values;
1 <?php 2 3 namespace template_engine\components\html\component_input; 4 5 use template_engine\components\html\FieldComponent; 6 use template_engine\element\CMSElement; 7 use template_engine\element\HtmlElement; 8 use template_engine\element\PHPBlockElement; 9 use template_engine\element\Value; 10 use template_engine\element\ValueExpression; 11 12 class InputComponent extends FieldComponent 13 { 14 public $default; 15 16 /** 17 * a list with purpose values. 18 * @var string 19 */ 20 public $list; 21 22 public $type = 'text'; 23 24 public $index; 25 26 public $name; 27 28 public $prefix; 29 30 public $value; 31 32 public $size; 33 34 public $minlength = 0; 35 public $maxlength = 256; 36 37 public $onchange; 38 39 public $hint; 40 41 public $icon; 42 43 public $required = false; 44 45 public $focus = false; 46 47 public $label; 48 49 50 51 public function createElement() 52 { 53 $input = (new CMSElement('input')); 54 55 $input->addAttribute('name',$this->name); 56 if ( $this->readonly ) 57 $input->addAttribute('disabled','disabled'); 58 59 if ( $this->required ) 60 $input->addAttribute( 'required','required'); 61 62 if ( $this->hint ) 63 $input->addAttribute( 'placeholder',$this->hint ); 64 65 if($this->focus) 66 $input->addAttribute( 'autofocus','autofocus'); 67 68 69 $input->addAttribute('type',$this->type); 70 $input->addAttribute('maxlength',$this->maxlength); 71 72 if ( $this->minlength ) 73 $input->addAttribute('minlength',$this->minlength); 74 75 if ( $this->class ) 76 $input->addStyleClass($this->class); 77 78 if (isset($this->default)) 79 $input->addAttribute('value',$this->default); 80 else 81 $input->addAttribute('value',Value::createExpression(ValueExpression::TYPE_DATA_VAR,$this->name)); 82 83 $input->addStyleClass('input'); 84 85 $datalist = null; 86 if ( $this->list ) { 87 88 $datalist = (new HtmlElement('datalist'))->addAttribute('id',$this->name.'_list'); 89 $optionLoop = (new PHPBlockElement())->asChildOf($datalist); 90 91 // Create the option list. 92 $optionLoop->beforeBlock = 'foreach($'.$this->list.' as $_value)'; 93 $option = (new CMSElement('option')) 94 ->addAttribute('value',Value::createExpression( ValueExpression::TYPE_DATA_VAR,'_value')); 95 96 $optionLoop->addChild($option); 97 } 98 99 100 if ( $this->label ) { 101 $label = new CMSElement('label'); 102 $label->addStyleClass('form-row')->addStyleClass('form-input'); 103 $label->addChild( (new CMSElement('span'))->addStyleClass('form-label')->content($this->label)); 104 $input->asChildOf($label); 105 106 if ( $datalist ) { 107 $label->addChild($datalist); 108 $input->addAttribute('list',$this->name.'_list'); 109 } 110 111 return $label; 112 } 113 114 return $input; 115 } 116 }
Downloadmodules/template_engine/components/html/component_input/InputComponent.class.php
History Tue, 14 Jan 2025 01:57:22 +0100 Jan Dankert New: Some new template element types like 'url','email','range','password','date','time', ...; New: datalists for input fields; Refactoring: Cleaner templates and actions for editing values; 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.