Fix: Re-initialize CKEditor after Save Discharge Advice button

ISSUE 2: After clicking 'Save Discharge Advice', CKEditor turns into plain textarea

ROOT CAUSE: initInstructionTools() was not re-initializing CKEditor after AJAX section reload
- When user clicks button with data-reload-section='section-instructions'
- Form submits via AJAX, returns updated HTML
- Section content replaced with new HTML
- initInstructionTools() called but did NOT restore CKEditor
- Fields remain as plain textareas

SOLUTION: Added CKEditor re-initialization to initInstructionTools()

Changes to discharge_create.php initInstructionTools():
1. Check if CKEDITOR is available
2. Destroy existing instances first (instruction_other, instruction_remark)
3. Re-create CKEditor for both fields with same config
4. Prevents duplicate instances and ensures editors work after reload

TESTING:
- Type in instruction_remark or instruction_other
- Click 'Save Discharge Advice'
- After reload, both fields should still be CKEditor (not textarea)
- Can continue editing with toolbar

NOTE: Issue 1 (data mixing between fields) requires separate investigation
User can test with: php check_instruction_data.php to see actual DB values
This commit is contained in:
DevSoftTech Server 2026-06-07 19:48:33 +05:30
parent 69373af48c
commit c4932601f1
2 changed files with 56 additions and 0 deletions

View File

@ -3569,6 +3569,40 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller
}
section.dataset.toolsBound = '1';
// Re-initialize CKEditor for instruction fields after section reload
if (typeof CKEDITOR !== 'undefined') {
// Destroy existing instances first to avoid duplication
if (CKEDITOR.instances['instruction_other']) {
CKEDITOR.instances['instruction_other'].destroy(true);
}
if (CKEDITOR.instances['instruction_remark']) {
CKEDITOR.instances['instruction_remark'].destroy(true);
}
// Re-create CKEditor instances
if (document.getElementById('instruction_other')) {
CKEDITOR.replace('instruction_other', {
height: 120,
toolbar: [
{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline'] },
{ name: 'paragraph', items: ['NumberedList', 'BulletedList'] },
{ name: 'editing', items: ['Undo', 'Redo'] }
]
});
}
if (document.getElementById('instruction_remark')) {
CKEDITOR.replace('instruction_remark', {
height: 150,
toolbar: [
{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline'] },
{ name: 'paragraph', items: ['NumberedList', 'BulletedList'] },
{ name: 'editing', items: ['Undo', 'Redo'] }
]
});
}
}
var addSelectedBtn = section.querySelector('#btn_instruction_add_selected_food');
var clearBtn = section.querySelector('#btn_instruction_clear_food');
var remark = section.querySelector('#instruction_remark');

View File

@ -0,0 +1,22 @@
<?php
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR);
require __DIR__ . '/vendor/autoload.php';
// Bootstrap minimal CI4
$paths = new \Config\Paths();
$app = \CodeIgniter\Config\Services::codeigniter();
$app->initialize();
$db = \Config\Database::connect();
$row = $db->table('ipd_discharge_instructions')->where('ipd_id', 1007141)->get()->getRowArray();
if ($row) {
echo "=== IPD 1007141 - ipd_discharge_instructions ===" . PHP_EOL . PHP_EOL;
echo "comp_report (contains other_text JSON): " . PHP_EOL;
echo substr($row['comp_report'] ?? '', 0, 300) . PHP_EOL . PHP_EOL;
echo "comp_remark (Discharge Summary field): " . PHP_EOL;
echo substr($row['comp_remark'] ?? '', 0, 300) . PHP_EOL;
} else {
echo "No record found for IPD 1007141" . PHP_EOL;
}