Skip to content

Commit 087105e

Browse files
author
arutyunyan
committed
add events
1 parent 58ee4cf commit 087105e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/frontend/example/TodoList.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ class="form-control"
2121
.'>
2222
<button
2323
type="button"
24-
class="btn btn-primary">
24+
class="btn btn-primary"'.
25+
$this->event('onclick', function () {
26+
return $this->setState(['task' => null]);
27+
})
28+
.'>
2529
<i class="bi bi-plus"></i>
2630
</button>
2731
</div>

src/frontend/html/component/Component.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function setState($obj)
4242
{
4343
$s = [];
4444
foreach ($obj as $prop => $value) {
45+
if (is_null($value)) {
46+
$value = "null";
47+
}
4548
$s[] = "$prop:$value";
4649
}
4750
return $this->className().'.setState({'.implode(',', $s).'})';
@@ -144,6 +147,11 @@ public function inputValue($name)
144147
return ' id="'.$id.'"';
145148
}
146149

150+
public function event($event, $callback)
151+
{
152+
return $event.'="'.$callback().'"';
153+
}
154+
147155
public function range($start, $end, $callback)
148156
{
149157
$str = '';

0 commit comments

Comments
 (0)