Skip to content

Commit 638b1a9

Browse files
fix: several problems with checkboxes
1 parent 7728596 commit 638b1a9

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

phpmyfaq/admin/assets/src/content/overview.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export const handleFaqOverview = async () => {
6363
checkbox.checked = element.checked;
6464
if (checkbox.checked === true) {
6565
faqIds.push(checkbox.getAttribute('data-pmf-faq-id'));
66+
} else {
67+
faqIds.push(checkbox.getAttribute('data-pmf-faq-id'));
6668
}
6769
}
6870
});
@@ -91,9 +93,6 @@ export const handleFaqOverview = async () => {
9193
element.addEventListener('change', (event) => {
9294
event.preventDefault();
9395

94-
console.log(event.target);
95-
console.log('toggle active faqs');
96-
9796
const categoryId = event.target.getAttribute('data-pmf-category-id');
9897
const faqIds = [];
9998
const token = event.target.getAttribute('data-pmf-csrf');
@@ -105,6 +104,8 @@ export const handleFaqOverview = async () => {
105104
checkbox.checked = element.checked;
106105
if (checkbox.checked === true) {
107106
faqIds.push(checkbox.getAttribute('data-pmf-faq-id'));
107+
} else {
108+
faqIds.push(checkbox.getAttribute('data-pmf-faq-id'));
108109
}
109110
}
110111
});

phpmyfaq/admin/record.show.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
$numRecordsByCat = $categoryRelation->getNumberOfFaqsPerCategory();
106106

107107
$numActiveByCat = [];
108+
$numStickyByCat = [];
108109

109110
$csrfToken = Token::getInstance()->getTokenString('faq-overview');
110111

@@ -134,7 +135,11 @@
134135
if (!isset($numActiveByCat[$record['category_id']])) {
135136
$numActiveByCat[$record['category_id']] = 0;
136137
}
138+
if (!isset($numStickyByCat[$record['category_id']])) {
139+
$numStickyByCat[$record['category_id']] = 0;
140+
}
137141
$numActiveByCat[$record['category_id']] += $record['active'] == 'yes' ? 1 : 0;
142+
$numStickyByCat[$record['category_id']] += $record['sticky'];
138143
}
139144
} else {
140145
$fdTable = Database::getTablePrefix() . 'faqdata';
@@ -324,7 +329,15 @@
324329
<div class="form-check">
325330
<input class="form-check-input pmf-admin-faqs-all-sticky" type="checkbox" value=""
326331
data-pmf-category-id="<?= $cid ?>" data-pmf-csrf="<?= $csrfToken ?>"
327-
id="sticky_category_block_<?= $cid ?>">
332+
id="sticky_category_block_<?= $cid ?>"
333+
<?php
334+
if (
335+
isset($numRecordsByCat[$cid]) && isset($numStickyByCat[$cid]) &&
336+
$numRecordsByCat[$cid] === $numStickyByCat[$cid]
337+
) {
338+
echo 'checked';
339+
}
340+
?>>
328341
<label class="form-check-label" for="sticky_category_block_<?= $cid ?>">
329342
<?= Translation::get('ad_record_sticky') ?>
330343
</label>

0 commit comments

Comments
 (0)