Skip to content

Commit 83bb22f

Browse files
committed
Fix toggle switches not being saved on modern MikoPBX
Fomantic's form('get values') no longer serializes toggle checkboxes reliably (unchecked toggles are omitted from the payload), so the is_post / is_1c switches were never persisted. Read each checkbox state explicitly in cbBeforeSendForm and send it as '1'/'0', mirroring ModuleLdapSync, and accept both 'on' and '1' in the save controller.
1 parent 29da027 commit 83bb22f

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

App/Controllers/ModuleCallTrackingController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function saveAction(): void
6565
case "is_1c":
6666
case "is_post":
6767
if (array_key_exists($key, $data)) {
68-
$record->$key = ($data[$key] == 'on') ? "1" : "0";
68+
$record->$key = in_array($data[$key], ['on', '1'], true) ? "1" : "0";
6969
} else {
7070
$record->$key = "0";
7171
}

public/assets/js/module-calltracking-index.js

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/js/src/module-calltracking-index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ const ModuleCallTracking = {
4242
cbBeforeSendForm(settings) {
4343
const result = settings;
4444
result.data = ModuleCallTracking.$formObj.form('get values');
45+
46+
// Fomantic's `form('get values')` does not reliably serialize toggle
47+
// checkboxes on modern MikoPBX (unchecked toggles are omitted), so read
48+
// each checkbox state explicitly and send it as '1' / '0'.
49+
ModuleCallTracking.$formObj.find('.checkbox').each((index, obj) => {
50+
const input = $(obj).find('input');
51+
const id = input.attr('id');
52+
if ($(obj).checkbox('is checked')) {
53+
result.data[id] = '1';
54+
} else {
55+
result.data[id] = '0';
56+
}
57+
});
58+
4559
return result;
4660
},
4761
cbAfterSendForm() {

0 commit comments

Comments
 (0)