Skip to content

Commit 2cabacf

Browse files
osbreadriaandotcom
authored andcommitted
Set the checkbox default in the UI when empty
1 parent ca97b48 commit 2cabacf

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ protected function defineAdminPage(): void
101101
->docs('https://docs.simpleanalytics.com/bypass-ad-blockers');
102102

103103
$tab->checkbox(SettingName::ENABLED, 'Enabled')
104+
->default(true)
104105
->description('Enable or disable Simple Analytics on your website.');
105106
})
106107
->tab('Ignore Rules', function (Tab $tab) {

src/Settings/Blocks/Fields/Checkbox.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Checkbox extends Field
1010
{
1111
use HasDocs;
1212

13+
protected bool $default = false;
14+
1315
public function getValueSanitizer(): callable
1416
{
1517
return 'absint';
@@ -20,6 +22,13 @@ public function getValueType(): string
2022
return 'integer';
2123
}
2224

25+
public function default(bool $value): self
26+
{
27+
$this->default = $value;
28+
29+
return $this;
30+
}
31+
2332
public function render(): void
2433
{
2534
?>
@@ -36,7 +45,7 @@ public function render(): void
3645
value="1"
3746
class="h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary"
3847
<?php
39-
if (Setting::get($this->getKey())) echo 'checked';
48+
if (Setting::boolean($this->getKey(), $this->default) === true) echo 'checked';
4049
?>
4150
>
4251
</div>

0 commit comments

Comments
 (0)