-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix storing checkbox values in local storage
- Loading branch information
1 parent
afb7a71
commit 339dbe3
Showing
6 changed files
with
64 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* This file is part of the package magicsunday/webtrees-pedigree-chart. | ||
* This file is part of the package magicsunday/webtrees-descendants-chart. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file distributed with this source code. | ||
|
@@ -10,7 +10,7 @@ | |
* | ||
* @author Rico Sonntag <[email protected]> | ||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License v3.0 | ||
* @link https://github.com/magicsunday/webtrees-pedigree-chart/ | ||
* @link https://github.com/magicsunday/webtrees-descendants-chart/ | ||
*/ | ||
export class Storage | ||
{ | ||
|
@@ -32,10 +32,16 @@ export class Storage | |
*/ | ||
register(name) | ||
{ | ||
let input = document.getElementById(name); | ||
// Use "querySelector" here as the ID of a checkbox elements may additionally contain a hyphen and the value | ||
let input = document.querySelector('[id^="' + name + '"]'); | ||
|
||
if (input === null) { | ||
return; | ||
} | ||
|
||
let storedValue = this.read(name); | ||
|
||
if (storedValue) { | ||
if (storedValue !== null) { | ||
if (input.type && (input.type === "checkbox")) { | ||
input.checked = storedValue; | ||
} else { | ||
|
@@ -70,11 +76,15 @@ export class Storage | |
* | ||
* @param {String} name The id or name of an HTML element | ||
* | ||
* @returns {String|Boolean|Number} | ||
* @returns {null|String|Boolean|Number} | ||
*/ | ||
read(name) | ||
{ | ||
return this._storage[name]; | ||
if (this._storage.hasOwnProperty(name)) { | ||
return this._storage[name]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the package magicsunday/webtrees-pedigree-chart. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Extends the default checkbox component with a hidden input field used to submit a default value | ||
* if the checkbox is not checked, otherwise the submitted form won't contain the checkbox value. | ||
* | ||
* @var bool|null $checked | ||
* @var bool|null $disabled | ||
* @var string|null $id | ||
* @var string $label | ||
* @var string $name | ||
* @var string $value | ||
* @var string $unchecked | ||
*/ | ||
|
||
?> | ||
|
||
<input type="hidden" value="<?= e($unchecked) ?>" name="<?= e($name) ?>"> | ||
|
||
<?= | ||
view('components/checkbox', [ | ||
'checked' => $checked ?? null, | ||
'disabled' => $disabled ?? null, | ||
'id' => $id ?? null, | ||
'label' => $label, | ||
'name' => $name, | ||
'value' => $value ?? '1', | ||
'unchecked' => $unchecked, | ||
]) | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters