BUGFIX: Event handlers were only attached on initial page load
PROBLEM: After implementing editable complaint fields, the inputs
wouldn't become editable when adding new complaints via the Smart
Complaints Picker. The event handlers were only attached once on
page load, not after the section was dynamically reloaded.
ROOT CAUSE: When clicking Add or AI Draft buttons, the form submits
and the section-complaints area is reloaded from server. The new
complaint rows had the input fields but no event handlers attached.
SOLUTION:
1. Moved event handler attachment logic into initComplaintTools()
function as new attachComplaintFieldHandlers() helper
2. This function is automatically called after section reload
3. Clone-and-replace pattern to prevent duplicate event handlers
4. Fixed table name: ipd_discharge_complaint (not ipd_discharge_comp)
FLOW:
- Add complaint → section reloads → initComplaintTools() runs →
attachComplaintFieldHandlers() attaches blur/keydown handlers →
editable fields work
Now clicking on complaint name/remark inputs works for both:
- Existing complaints (on page load)
- Newly added complaints (after section reload)
FEATURE: Inline editing for discharge complaint table
PROBLEM: In IPD discharge form, complaint names and remarks were
read-only after adding. Unlike OPD consult form where you can edit
complaint names directly in the table.
SOLUTION:
1. VIEW Changes (discharge_create.php):
- Changed complaint name and remark columns from static <td> to editable <input>
- Added data attributes for complaint ID and original values
- Added CSS classes: discharge-complaint-name-input, discharge-complaint-remark-input
2. JAVASCRIPT Changes:
- Added saveComplaintField() function for AJAX updates
- Event handlers on blur to save changes
- Enter key support to blur and save
- Visual feedback: green border on success, red on error
- Auto-updates original value after successful save
3. CONTROLLER Changes (Ipd_discharge.php):
- Added update_complaint_field() method for AJAX endpoint
- Updates ipd_discharge_comp table (comp_report or comp_remark)
- Returns JSON success/error response
BENEFITS:
- Same user experience as OPD consult form
- Edit complaints/remarks without page reload
- Immediate feedback on save success/failure
- Type correction and updates without removing and re-adding rows