openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

InputComponent.class.php (1831B)


      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\Value;
      9 use template_engine\element\ValueExpression;
     10 
     11 class InputComponent extends FieldComponent
     12 {
     13 	public $default;
     14 
     15 	public $type = 'text';
     16 
     17 	public $index;
     18 
     19 	public $name;
     20 
     21 	public $prefix;
     22 
     23 	public $value;
     24 
     25 	public $size;
     26 
     27 	public $minlength = 0;
     28 	public $maxlength = 256;
     29 
     30 	public $onchange;
     31 
     32 	public $hint;
     33 
     34 	public $icon;
     35 
     36 	public $required = false;
     37 
     38 	public $focus = false;
     39 
     40 	public $label;
     41 
     42 
     43 
     44 	public function createElement()
     45 	{
     46 		$input = (new CMSElement('input'));
     47 
     48 		$input->addAttribute('name',$this->name);
     49 		if   ( $this->readonly )
     50 			$input->addAttribute('disabled','disabled');
     51 
     52 		if   ( $this->required )
     53 			$input->addAttribute( 'required','required');
     54 
     55 		if ( $this->hint )
     56 			$input->addAttribute( 'placeholder',$this->hint );
     57 			
     58 		if($this->focus)
     59 			$input->addAttribute( 'autofocus','autofocus');
     60 
     61 
     62 		$input->addAttribute('type',$this->type);
     63 		$input->addAttribute('maxlength',$this->maxlength);
     64 
     65 		if   ( $this->minlength )
     66 			$input->addAttribute('minlength',$this->minlength);
     67 
     68 		if   ( $this->class )
     69 			$input->addStyleClass($this->class);
     70 			
     71 		if (isset($this->default))
     72 			$input->addAttribute('value',$this->default);
     73 		else
     74 			$input->addAttribute('value',Value::createExpression(ValueExpression::TYPE_DATA_VAR,$this->name));
     75 
     76 		$input->addStyleClass('input');
     77 
     78 		if   ( $this->label ) {
     79 			$label = new CMSElement('label');
     80 			$label->addStyleClass('form-row')->addStyleClass('form-input');
     81 			$label->addChild( (new CMSElement('span'))->addStyleClass('form-label')->content($this->label));
     82 			$input->asChildOf($label);
     83 			return $label;
     84 		}
     85 
     86 		return $input;
     87 	}
     88 }