devsofttech_hms_ci4/app/Views/Setting
DevSoftTech Server 1da16a54d6 Fix CKEditor initialization issues in discharge template editor
Fixed the error: Uncaught TypeError: can't access property 'getElementsByTag', b is null

Root Cause:
- CKEditor was not properly destroyed before reinitialization
- No error handling for editor state transitions
- Missing timing delays for DOM readiness when loaded via AJAX
- Inconsistent checking for CKEditor availability

Improvements:
1. Safe destroy pattern - wrap destroy() in try-catch to handle state issues
2. Added typeof check for CKEDITOR instead of window.CKEDITOR
3. Added 100ms setTimeout delay before CKEDITOR.replace() to ensure cleanup
4. Added 150ms delay for initial editor load (especially for AJAX loads)
5. Wrapped all setData() calls in try-catch with textarea fallback
6. Added console warnings for debugging instead of silent failures
7. Check document.readyState before initialization
8. Re-initialize editor check after AJAX template load
9. Added element existence validation before replace()

Changes follow the working pattern from:
- app/Views/PathLab_Report/ultrasound_report_edit.php (safeReplace pattern)
- app/Views/diagnosis/lab_final_report_editor.php (typeof checks)

This ensures the editor works properly when:
- Page loads normally
- Page loads via AJAX (load_form_div)
- User switches between templates using Edit button
- User cancels edit and resets form

Tested scenarios:
- Initial page load
- Edit template -> load data -> CKEditor shows content
- Cancel -> CKEditor resets
- Multiple edit/cancel cycles
2026-06-06 12:51:21 +05:30
..
Admin Add pharmacy invoice permissions and discount print fixes 2026-06-01 10:13:40 +05:30
Bank Implement OPD template builder, doctor template selection, and OPD print integration fixes 2026-02-27 19:44:36 +05:30
Bed refactor: set number input step to 1 across views 2026-04-10 21:16:25 +05:30
Charges feat(ipd-charges): group delete, sort order, Up/Down buttons, foldable billing panels 2026-04-18 06:56:38 +05:30
Doctor feat: add HealthPlix OPD sync flow with settings, diagnostics, and sync ID persistence 2026-04-27 08:32:51 +05:30
Insurance Fix legacy billing prints and pathology template compatibility 2026-03-21 02:23:31 +05:30
MedicalBank Implement OPD template builder, doctor template selection, and OPD print integration fixes 2026-02-27 19:44:36 +05:30
Reffer Implement OPD template builder, doctor template selection, and OPD print integration fixes 2026-02-27 19:44:36 +05:30
Stock refactor: set number input step to 1 across views 2026-04-10 21:16:25 +05:30
Template Fix CKEditor initialization issues in discharge template editor 2026-06-06 12:51:21 +05:30