fix label setLabel

This commit is contained in:
kali 2024-03-18 13:25:38 +03:00
parent 1d20c0863b
commit a73c5e8170
8 changed files with 53 additions and 18 deletions

View File

@ -3,6 +3,8 @@
use itguild\forms\Form;
use \itguild\forms\inputs\TextInput;
use \itguild\forms\inputs\Radio;
use \itguild\forms\inputs\Select;
use \itguild\forms\ActiveForm;
ini_set("display_errors", true);
error_reporting(-1);
@ -27,22 +29,22 @@ $form->select("select", ["class1" => "option", "class2" => "b2", "class3" => "b4
$form->button('button', "Кнопка", ["id" => "button"]);
$form->endForm();
$activeForm = new \itguild\forms\ActiveForm();
$activeForm = new ActiveForm();
$activeForm->field(class: TextInput::class, name: 'nnn', params: ["style" => "color:RED;display:flex"])
->setLabel("dfdfdffd")
->render();
$activeForm->field(class: TextInput::class, name: 'bbb', params: [])
->render();
$activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"])
->setOptions(['1' => 'bbb1', '2' => 'vvv3', 3 => 'ggg3', 4 => 'fgfgfgfg4'])
->setLabel("bbb222bbb")
->render();
$activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"])
->setLabel("bbbbbb")
->render();
$activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"])
->setOptions(['1' => 'bbb1', '2' => 'vvv3', 3 => 'ggg3', 4 => 'fgfgfgfg4'])
->render();
$activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"])
->render();
$activeForm->field(\itguild\forms\inputs\Select::class, 'ddd', ['value' => 2])
$activeForm->field(Select::class, 'ddd', ['value' => 2])
->setOptions(['1' => 'bbb1', '2' => 'vvv3', 3 => 'ggg3', 4 => 'fgfgfgfg4'])
->render();

View File

@ -12,7 +12,8 @@ class Button extends BaseInput
private string $name;
private string $value;
private array $paramsArray;
private bool $hasLabel = false;
private string $labelTitle = '';
/**
* @param string $name
@ -33,6 +34,9 @@ class Button extends BaseInput
{
$paramsString = $this->createParams($this->paramsArray);
$this->html = "<button name='$this->name' $paramsString>$this->value</button>";
if($this->hasLabel == true) {
$this->html = "<label>$this->labelTitle</label> $this->html";
}
return $this;
}
@ -54,7 +58,9 @@ class Button extends BaseInput
*/
public function setLabel(string $title): self
{
$this->html = "<label>$title $this->html</label>";
$this->hasLabel = true;
$this->labelTitle = $title;
return $this;
}

View File

@ -12,6 +12,8 @@ class Checkbox extends BaseInput
private string $name;
private string $value;
private array $paramsArray;
private bool $hasLabel = false;
private string $labelTitle = '';
/**
@ -33,6 +35,10 @@ class Checkbox extends BaseInput
{
$paramsString = $this->createParams($this->paramsArray);
$this->html = "<input name='$this->name' type='checkbox' value='$this->value' $paramsString >";
if($this->hasLabel == true) {
$this->html = "<label>$this->labelTitle</label> $this->html";
}
return $this;
}
@ -55,7 +61,9 @@ class Checkbox extends BaseInput
*/
public function setLabel(string $title): self
{
$this->html = "<label>$title $this->html</label>";
$this->hasLabel = true;
$this->labelTitle = $title;
return $this;
}
}

View File

@ -31,6 +31,7 @@ class Label extends BaseInput
$paramsString = $this->createParams($this->paramsArray);
$this->html = "<label $paramsString >$this->title</label>";
return $this;
}

View File

@ -28,8 +28,10 @@ class Radio extends BaseInput
{
$paramsString = $this->createParams($this->paramsArray);
$optionsString = $this->createOption($this->options, $this->value);
$this->html = "<input name='$this->name' type='radio' $paramsString>$optionsString</input>";
$this->html = "<label>$this->labelTitle</label> $this->html";
$this->html = "<input name='$this->name' type='radio' $paramsString>$optionsString";
if($this->hasLabel == true) {
$this->html = "<label>$this->labelTitle</label> $this->html";
}
return $this;
}

View File

@ -42,7 +42,9 @@ class Select extends BaseInput
$paramsString = $this->createParams($this->paramsArray);
$optionsString = $this->createOption($this->options, $this->value);
$this->html = "<select name='$this->name' $paramsString>$optionsString</select>";
$this->html = "<label>$this->labelTitle</label> $this->html";
if($this->hasLabel == true) {
$this->html = "<label>$this->labelTitle</label> $this->html";
}
return $this;

View File

@ -12,6 +12,8 @@ class TextArea extends BaseInput
private $name;
private $value;
private $paramsArray;
private bool $hasLabel = false;
private string $labelTitle = '';
/**
* @param string $name
@ -32,6 +34,9 @@ class TextArea extends BaseInput
{
$paramsString = $this->createParams($this->paramsArray);
$this->html = "<textarea name='$this->name' $paramsString>$this->value</textarea>";
if($this->hasLabel == true) {
$this->html = "<label>$this->labelTitle</label> $this->html";
}
return $this;
}
@ -55,7 +60,9 @@ class TextArea extends BaseInput
*/
public function setLabel(string $title): self
{
$this->html = "<label>$title $this->html</label>";
$this->hasLabel = true;
$this->labelTitle = $title;
return $this;
}

View File

@ -11,6 +11,8 @@ class TextInput extends BaseInput
use CreateParams;
private string $name;
private bool $hasLabel = false;
private string $labelTitle = '';
private array $paramsArray;
@ -31,6 +33,9 @@ class TextInput extends BaseInput
{
$paramsString = $this->createParams($this->paramsArray);
$this->html = "<input name='$this->name' $paramsString >";
if($this->hasLabel == true) {
$this->html = "<label>$this->labelTitle</label> $this->html";
}
return $this;
}
@ -53,7 +58,9 @@ class TextInput extends BaseInput
*/
public function setLabel(string $title): self
{
$this->html = "<label>$title $this->html</label>";
$this->hasLabel = true;
$this->labelTitle = $title;
return $this;
}