add id and label
This commit is contained in:
parent
ead22b395a
commit
4b2927860e
|
@ -16,6 +16,17 @@ class Element{
|
||||||
|
|
||||||
public function name() : string{ return $this->data['name']; }
|
public function name() : string{ return $this->data['name']; }
|
||||||
|
|
||||||
|
public function id(string $id): self{
|
||||||
|
$this->data['id'] = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function label(string $label, string $more = ''): self {
|
||||||
|
$this->data['label'] = $label;
|
||||||
|
$this->data['label.more'] = $more;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function required(bool $value = true) : self{
|
public function required(bool $value = true) : self{
|
||||||
$this->data['required'] = $value;
|
$this->data['required'] = $value;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -42,7 +53,15 @@ class Element{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getId(): string{
|
||||||
|
return isset($this->data['id']) ? $this->data['id'] : $this->data['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function htmlLabel(): string{
|
||||||
|
return isset($this->data['label']) ? '<label for="'.$this->getId().'" '.$this->data['label.more'].'>'.$this->data['label']."</label>\n" : '';
|
||||||
|
}
|
||||||
|
|
||||||
public function html(string $more = '') : string{
|
public function html(string $more = '') : string{
|
||||||
return '<span '.$more.'></span>';
|
return $this->htmlLabel().'<span '.$more.'></span>';
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -135,7 +135,9 @@ class Input extends Element{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function html(string $more = '') : string{
|
public function html(string $more = '') : string{
|
||||||
return '<input name="'.$this->data['name'].'" '.
|
return $this->htmlLabel().
|
||||||
|
'<input name="'.$this->data['name'].'" '.
|
||||||
|
'id="'.$this->getId().'" '.
|
||||||
(isset($this->data['value']) && !(isset($this->data['password']) && $this->data['password'] == true) ? 'value="'.$this->data['value'].'" ' : '').
|
(isset($this->data['value']) && !(isset($this->data['password']) && $this->data['password'] == true) ? 'value="'.$this->data['value'].'" ' : '').
|
||||||
(isset($this->data['type']) ? 'type="'.$this->data['type'].'" ' : '').
|
(isset($this->data['type']) ? 'type="'.$this->data['type'].'" ' : '').
|
||||||
(isset($this->data['title']) ? 'title="'.$this->data['title'].'" ' : '').
|
(isset($this->data['title']) ? 'title="'.$this->data['title'].'" ' : '').
|
||||||
|
|
|
@ -62,7 +62,9 @@ class Select extends Element{
|
||||||
$options .= $option['more'].'>'.$option['text'].'</option>';
|
$options .= $option['more'].'>'.$option['text'].'</option>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$html = '<select name="'.$this->data['name'].'" ';
|
$html = $this->htmlLabel().
|
||||||
|
'<select name="'.$this->data['name'].'" '.
|
||||||
|
'id="'.$this->getId().'" ';
|
||||||
$inputmore = '';
|
$inputmore = '';
|
||||||
if(isset($this->data['other.text'])){
|
if(isset($this->data['other.text'])){
|
||||||
$options .= '<option value="'.$this->data['other.text'].'" '.(isset($this->data['value']) && $selected == false ? 'selected="selected" ' : '').'>'.$this->data['other.text'].'</option>';
|
$options .= '<option value="'.$this->data['other.text'].'" '.(isset($this->data['value']) && $selected == false ? 'selected="selected" ' : '').'>'.$this->data['other.text'].'</option>';
|
||||||
|
|
|
@ -8,7 +8,9 @@ class TextArea extends Element{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function html(string $more = '') : string{
|
public function html(string $more = '') : string{
|
||||||
return '<textarea name="'.$this->data['name'].'" '.
|
return $this->htmlLabel().
|
||||||
|
'<textarea name="'.$this->data['name'].'" '.
|
||||||
|
'id="'.$this->getId().'" '.
|
||||||
(isset($this->data['value']) ? 'value="'.$this->data['value'].'" ' : '').
|
(isset($this->data['value']) ? 'value="'.$this->data['value'].'" ' : '').
|
||||||
(isset($this->data['required']) && $this->data['required'] == true ? 'required ' : '').
|
(isset($this->data['required']) && $this->data['required'] == true ? 'required ' : '').
|
||||||
$more.'></textarea>';
|
$more.'></textarea>';
|
||||||
|
|
Loading…
Reference in New Issue