Skip to content

Commit

Permalink
Fixed disabled attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
vossik committed Jul 22, 2020
1 parent 10ca286 commit d2ed7c9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/Form/ResultObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class ResultObject implements \JsonSerializable
private int $id;
private string $text;
private ?string $title = null;
private ?bool $disabled = null;
private bool $disabled;

public function __construct(int $id, string $text, ?string $title = null, ?bool $disabled = null)
public function __construct(int $id, string $text, ?string $title = null, bool $disabled = false)
{
$this->id = $id;
$this->text = $text;
Expand All @@ -39,6 +39,11 @@ public function getText() : string
return $this->text;
}

public function isDisabled() : bool
{
return $this->disabled;
}

public function jsonSerialize()
{
$toReturn = [
Expand All @@ -50,7 +55,7 @@ public function jsonSerialize()
$toReturn['title'] = $this->title;
}

if ($this->disabled !== null) {
if ($this->disabled === true) {
$toReturn['disabled'] = $this->disabled;
}

Expand Down
13 changes: 13 additions & 0 deletions src/Form/ResultObjectSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ public function getRawData() : array
return $toReturn;
}

public function getDisabled() : array
{
$toReturn = [];

foreach ($this as $object) {
if ($object->isDisabled()) {
$toReturn[] = $object->getId();
}
}

return $toReturn;
}

public function current() : \Nepttune\Form\ResultObject
{
return parent::current();
Expand Down
4 changes: 2 additions & 2 deletions src/Form/TAjaxSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ trait TAjaxSelect
/** @var \Nette\Caching\Cache */
private $storage;

/** @var array */
private $optionsRaw;

public function setCallback(callable $callback): self
Expand Down Expand Up @@ -100,7 +99,7 @@ public function signalReceived(string $signal): void
/**
* @param string $query
* @param array|int|null $default
* @return \Nepttune\Form\ResultObjectSet
* @return array
*/
private function getData(string $query = '', $default = null) : \Nepttune\Form\ResultObjectSet
{
Expand Down Expand Up @@ -150,6 +149,7 @@ private function initiateItems($value = null): void
}

parent::setItems($data->getRawData());
parent::setDisabled($data->getDisabled());
}

private function fireOnchange($selected = null) : void
Expand Down

0 comments on commit d2ed7c9

Please sign in to comment.