devsofttech_hms_ci4/app/Views/Setting/Template
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
..
diagnosis_print_settings.php refactor: set number input step to 1 across views 2026-04-10 21:16:25 +05:30
discharge_templates.php Fix CKEditor initialization issues in discharge template editor 2026-06-06 12:51:21 +05:30
document_print_settings.php Add placeholder panel to document print settings; autocomplete off on med inputs; localStorage medicine cache 2026-04-09 03:43:53 +05:30
index.php Refine OPD template builder UI and preview behavior 2026-06-05 03:34:08 +05:30
ipd_document_templates.php Make IPD forms dynamic and stop stale OPD refresh polling 2026-04-08 11:41:33 +05:30