Skip to content

Commit

Permalink
Merge pull request #4 from Zhyltix/master
Browse files Browse the repository at this point in the history
Create disabled functionality for formal
  • Loading branch information
spidfire authored Jul 27, 2021
2 parents 0c0045c + f9a1a9b commit e4708f2
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 11 deletions.
18 changes: 18 additions & 0 deletions src/FormAl/ElementBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ abstract class ElementBase
private $folded = false;
/** @var bool */
protected $hasAutoFill = true;
/** @var bool */
protected $disabled = false;

/**
* @return string
Expand Down Expand Up @@ -267,6 +269,22 @@ public function isFolded()
return $this->folded;
}

/**
* @param bool $bool
*/
public function setDisabled($bool)
{
$this->disabled = $bool;
}

/**
* @return bool
*/
public function isDisabled()
{
return $this->disabled;
}

/**
* @return string|null
*/
Expand Down
4 changes: 4 additions & 0 deletions src/FormAl/Elements/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function render()
->attr('style', "max-width: 400px;")
->addText($this->text);

if ($this->isDisabled()) {
$element->attr('disabled', true);
}

return $element->render();
}
}
4 changes: 4 additions & 0 deletions src/FormAl/Elements/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public function render()
->attr('checked', $checked)
->attr('value', $this->trueValue);

if ($this->isDisabled()) {
$element->attr('disabled', true);
}

$tooltip = "";
if (empty($this->getTooltip()) == false) {
$tooltip = " " . $this->getTooltip();
Expand Down
4 changes: 4 additions & 0 deletions src/FormAl/Elements/Chosen.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function render()
$element->attr('multiple', 'multiple');
$element->attr('class', 'chosen-select form-control');

if ($this->isDisabled()) {
$element->attr('disabled', 'disabled');
}

$this->optGroups($element, $this->options);

return $element->render() . "<script type='text/javascript'>
Expand Down
6 changes: 5 additions & 1 deletion src/FormAl/Elements/Colorpicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ public function render()
->attr('id', $this->getName())
->attr('value', $this->getValue());

$element->add('input')
$colorpicker = $element->add('input')
->attr('name', $this->getName())
->attr('type', "text")
->attr('value', $this->getValue())
->attr('class', "form-control")
->attr('style', "display:inline; width: 366px;");

if ($this->isDisabled()) {
$colorpicker->attr('disabled', 'disabled');
}

$element->add('span')
->attr('class', "input-group-addon")
->attr(
Expand Down
4 changes: 4 additions & 0 deletions src/FormAl/Elements/DateNoTimepicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public function render()
->attr('value', $this->getValue());
//->attr('style', 'height: 32px; width: 400px;');

if ($this->isDisabled()) {
$element->attr('disabled', 'disabled');
}

if (isset($_COOKIE['lang'])) {
$lang = explode('_', $_COOKIE['lang']);
$lang = $lang[0];
Expand Down
9 changes: 1 addition & 8 deletions src/FormAl/Elements/Datepicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ class Datepicker extends ElementBase
/** @var bool */
private $isRequired = false;

/** @var bool */
private $isDisabled = false;

public function setDisabled(bool $disabled){
$this->isDisabled = $disabled;
}

/**
* @param string $text
*
Expand Down Expand Up @@ -85,7 +78,7 @@ public function render()
->attr('name', $this->getName())
->attr('id', $this->getName());

if($this->isDisabled){
if($this->isDisabled()){
$element->attr('disabled', 'disabled');
}

Expand Down
4 changes: 4 additions & 0 deletions src/FormAl/Elements/ImageUploadToServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public function render()
->attr('type', 'file')
->attr('name', $this->getName())
->attr('accept', "image/*");

if ($this->isDisabled()) {
$element->attr('disabled', 'disabled');
}
}

return $element->render();
Expand Down
4 changes: 4 additions & 0 deletions src/FormAl/Elements/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public function render()
$element->attr('maxlength', $this->maxLength);
}

if ($this->isDisabled()) {
$element->attr('disabled', 'disabled');
}

if (!$this->hasAutoFill) {
$element->attr('readonly', 'true')
->attr('onfocus', 'javascript:this.removeAttribute(\'readonly\');')
Expand Down
4 changes: 4 additions & 0 deletions src/FormAl/Elements/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function render()
->attr('name', $this->getName())
->attr('value', $this->getValue());

if ($this->isDisabled()) {
$element->attr('disabled', 'disabled');
}

return $element->render();
}

Expand Down
4 changes: 4 additions & 0 deletions src/FormAl/Elements/MultiSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public function optGroups(HtmlBuilder $builder, $data)
->attr('value', "true")
->attr('name', $this->getName() . "[" . $key . "]");

if ($this->isDisabled()) {
$label->attr('disabled', 'disabled');
}

$label->addText($value);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/FormAl/Elements/PositiveInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public function render()
->attr('min', '1')
->attr('value', $this->getValue());

if ($this->isDisabled()) {
$element->attr('disabled', 'disabled');
}

return $element->render();
}
}
5 changes: 4 additions & 1 deletion src/FormAl/Elements/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public function optGroups(HtmlBuilder $builder, $data)
)
->attr('value', $key)
->addText($value);


if ($this->isDisabled()) {
$builder->attr('disabled', 'disabled');
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/FormAl/Elements/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public function render()
$element = new HtmlBuilder('select.form-control');
$element->attr('name', $this->getName());

if ($this->isDisabled()) {
$element->attr('disabled', 'disabled');
}

$this->optGroups($element, $this->options);

return $element->render();
Expand Down
6 changes: 5 additions & 1 deletion src/FormAl/Elements/Textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public function render()
->attr('cols', $this->cols)
->attr('rows', $this->rows)
->addText($this->getValue());


if ($this->isDisabled()) {
$element->attr('disabled', 'disabled');
}

if ($this->fancy) {
return $element->render()
. '<script type="text/javascript">
Expand Down

0 comments on commit e4708f2

Please sign in to comment.