Skip to content

Commit d2ed7c9

Browse files
committed
Fixed disabled attribute
1 parent 10ca286 commit d2ed7c9

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/Form/ResultObject.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class ResultObject implements \JsonSerializable
1919
private int $id;
2020
private string $text;
2121
private ?string $title = null;
22-
private ?bool $disabled = null;
22+
private bool $disabled;
2323

24-
public function __construct(int $id, string $text, ?string $title = null, ?bool $disabled = null)
24+
public function __construct(int $id, string $text, ?string $title = null, bool $disabled = false)
2525
{
2626
$this->id = $id;
2727
$this->text = $text;
@@ -39,6 +39,11 @@ public function getText() : string
3939
return $this->text;
4040
}
4141

42+
public function isDisabled() : bool
43+
{
44+
return $this->disabled;
45+
}
46+
4247
public function jsonSerialize()
4348
{
4449
$toReturn = [
@@ -50,7 +55,7 @@ public function jsonSerialize()
5055
$toReturn['title'] = $this->title;
5156
}
5257

53-
if ($this->disabled !== null) {
58+
if ($this->disabled === true) {
5459
$toReturn['disabled'] = $this->disabled;
5560
}
5661

src/Form/ResultObjectSet.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ public function getRawData() : array
5757
return $toReturn;
5858
}
5959

60+
public function getDisabled() : array
61+
{
62+
$toReturn = [];
63+
64+
foreach ($this as $object) {
65+
if ($object->isDisabled()) {
66+
$toReturn[] = $object->getId();
67+
}
68+
}
69+
70+
return $toReturn;
71+
}
72+
6073
public function current() : \Nepttune\Form\ResultObject
6174
{
6275
return parent::current();

src/Form/TAjaxSelect.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ trait TAjaxSelect
2828
/** @var \Nette\Caching\Cache */
2929
private $storage;
3030

31-
/** @var array */
3231
private $optionsRaw;
3332

3433
public function setCallback(callable $callback): self
@@ -100,7 +99,7 @@ public function signalReceived(string $signal): void
10099
/**
101100
* @param string $query
102101
* @param array|int|null $default
103-
* @return \Nepttune\Form\ResultObjectSet
102+
* @return array
104103
*/
105104
private function getData(string $query = '', $default = null) : \Nepttune\Form\ResultObjectSet
106105
{
@@ -150,6 +149,7 @@ private function initiateItems($value = null): void
150149
}
151150

152151
parent::setItems($data->getRawData());
152+
parent::setDisabled($data->getDisabled());
153153
}
154154

155155
private function fireOnchange($selected = null) : void

0 commit comments

Comments
 (0)