Skip to content

Refactor: Remove jQuery DOM manipulation (Part 1) - Form resets, dead code, and cross-component toggles#76

Open
Anurag-elitx wants to merge 1 commit into
PSMRI:mainfrom
Anurag-elitx:remove-jquery-dom-manupulation
Open

Refactor: Remove jQuery DOM manipulation (Part 1) - Form resets, dead code, and cross-component toggles#76
Anurag-elitx wants to merge 1 commit into
PSMRI:mainfrom
Anurag-elitx:remove-jquery-dom-manupulation

Conversation

@Anurag-elitx

@Anurag-elitx Anurag-elitx commented May 16, 2026

Copy link
Copy Markdown

📋 Description

JIRA ID: #129

This PR represents the first major phase of eliminating legacy jQuery DOM manipulation across the Helpline104-UI application to reduce technical debt and safely prepare the codebase for the Angular 19 migration.

Key Changes:

  1. Form Resets: Replaced anti-pattern jQuery trigger("reset") calls with Angular's native resetForm() API using @ViewChild template references (e.g., within sio-blood-on-call-service.component.ts and case-sheet.component.ts).
  2. Dead Code Cleanup: Audited and removed redundant jQuery .css() styling calls (e.g., targeting #L1, #L2 IDs) that were attempting to mutate elements no longer present in the DOM across the sio-organ-donation-service and sio-blood-on-call-service components.
  3. Cross-Component Toggles: Eliminated cross-component DOM mutations where service-role-selection was triggering jQuery("#db_label").show/hide() on an element living in multi-role-screen. This has been refactored to use idiomatic Angular reactive state management (showDbLabel boolean property) governed by the sendHeaderStatus RxJS subscription and an *ngIf structural directive.

✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

  • Testing: Changes were implemented by statically mapping global jQuery() selectors to their respective native Angular properties and verifying that component logic (boolean flags controlling structural directives) remains functionally equivalent.
  • Due to the @angular/core node_modules installation error locally, static code analysis was relied upon to verify RxJS subscriptions and ViewChild resets.

Summary by CodeRabbit

  • Refactor
    • Removed jQuery dependencies across multiple components and replaced with Angular's native form APIs.
    • Updated form reset operations to use Angular's NgForm API instead of jQuery-based DOM manipulation.
    • Converted UI visibility and styling logic from direct jQuery DOM manipulation to component state management.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Systematic migration across 21 components from jQuery DOM manipulation to Angular form APIs and state management. Removes global jQuery declarations, replaces jQuery form resets with NgForm.resetForm(), removes jQuery CSS styling calls, and converts DOM visibility manipulation to Angular state binding.

Changes

jQuery to Angular form and state refactoring

Layer / File(s) Summary
Remove unused jQuery global declarations
src/app/104/104.component.ts, src/app/bp-screening-component/bp-screening-component.ts, src/app/diabetic-screening-component/diabetic-screening-component.ts, src/app/directory-services/directory-services.component.ts, src/app/outbound-search-records/outbound-search-records.component.ts, src/app/prescription/prescription.component.ts, src/app/sio-food-safety-service/sio-food-safety-service.component.ts, src/app/sio-services/sio-services.component.ts, src/app/supervisor-upload-schemes/supervisor-uploadSchemes.component.ts
Removes ambient declare var jQuery: any; declarations and unused commented-out jQuery code from 10 components.
COVID-19 form reset using Angular ViewChild
src/app/covid-19/covid-19.component.ts
Adds @ViewChild('covidForm') reference with NgForm type annotation, updates imports for ViewChild, and replaces jQuery form reset triggers with Angular resetForm() calls in both save and clear flows.
Beneficiary registration form resets
src/app/beneficiary-registration-104/beneficiary-registration-104.component.ts
Updates three form reset locations (calledEarlier, updateSuccessHandeler, regSuccessHandeler) from jQuery trigger("reset") to Angular resetForm().
Case sheet form reset
src/app/case-sheet/case-sheet.component.ts
Replaces jQuery form reset trigger with Angular NgForm.resetForm() in post-modal-close success handler.
Blood on call service form and styling refactoring
src/app/sio-blood-on-call-service/sio-blood-on-call-service.component.ts
Adds @ViewChild references for hospitalDetailForm and patientDetailsForm, converts form resets from jQuery to Angular resetForm(), and removes jQuery font-weight CSS styling from navigation methods.
SIO services form reset refactoring
src/app/sio-epidemic-outbreak-service/sio-epidemic-outbreak-service.component.ts, src/app/sio-grievience-service/sio-grievience-service.component.ts, src/app/sio-outbound-provider/sio-outbound-provider.component.ts
Updates imports to include ViewChild and NgForm, adds @ViewChild form references to three SIO service components, and replaces jQuery reset triggers with Angular resetForm() calls.
Organ donation service navigation styling removal
src/app/sio-organ-donation-service/sio-organ-donation-service.component.ts
Removes jQuery font-weight styling calls from jumpTo step navigation and outboundHospitals method while preserving component state visibility flags.
Multi-role screen label visibility state binding
src/app/multi-role-screen/multi-role-screen.component.html, src/app/multi-role-screen/multi-role-screen.component.ts
Replaces jQuery hide() with Angular state variable showDbLabel initialized in component and bound in template via *ngIf structural directive; subscription to sendHeaderStatus updates visibility state based on header name.
Service role selection dashboard navigation
src/app/service-role-selection/service-role-selection.component.ts
Removes jQuery show() call from route2dashboard before navigation.
Supervisor upload schemes form reset
src/app/supervisor-upload-schemes/supervisor-uploadSchemes.component.ts
Converts form resets in successHandler and createScheme from jQuery trigger("reset") to Angular resetForm().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 jQuery once ruled with DOM so grand,
But Angular's way is truly planned,
Forms now flow through ViewChild's grace,
State-bound views find their place,
Cleanup done, the code runs free!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely summarizes the main objective: removing jQuery DOM manipulation across multiple components in Part 1, with specific mentions of form resets, dead code removal, and cross-component toggles.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/app/multi-role-screen/multi-role-screen.component.ts (1)

134-138: ⚡ Quick win

Decouple visibility logic from display text literal.

This condition depends on "Role Selection" text, which is fragile if header text changes/localizes. Prefer a stable status key/enum from sendHeaderStatus and derive showDbLabel from that key.

♻️ Suggested adjustment
-      if (data === "Role Selection") {
-        this.showDbLabel = false;
-      } else {
-        this.showDbLabel = true;
-      }
+      // Prefer key-based contract from emitter, e.g. `data.headerKey`
+      this.showDbLabel = data !== "Role Selection";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/multi-role-screen/multi-role-screen.component.ts` around lines 134 -
138, The visibility check for showDbLabel relies on the display string "Role
Selection" which is fragile; update the component to use a stable status
key/enum from sendHeaderStatus instead: change the sendHeaderStatus payload to
include a status identifier (e.g., HeaderStatus.RoleSelection) and in
multi-role-screen.component.ts replace the string comparison with a check
against that identifier (e.g., compare data.status or the enum value), then set
this.showDbLabel based on the stable status key rather than the localized header
text.
src/app/supervisor-upload-schemes/supervisor-uploadSchemes.component.ts (1)

246-246: ⚡ Quick win

Consider adding null safety check before resetForm().

While the ViewChild should be initialized when these methods are called, adding a null safety check would prevent runtime errors if the form reference is missing or the ViewChild query fails.

🛡️ Suggested defensive check
 successHandler(response) {
   this.schemeData = response;
   this.notUploaded = false;
-  this.schemeForm.resetForm();
+  if (this.schemeForm) {
+    this.schemeForm.resetForm();
+  }
   var obj = {
 createScheme() {
   this.create = true;
   this.showTable = false;
-  this.schemeForm.resetForm();
+  if (this.schemeForm) {
+    this.schemeForm.resetForm();
+  }
 
 }

Also applies to: 278-278

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/supervisor-upload-schemes/supervisor-uploadSchemes.component.ts` at
line 246, Add a null/undefined guard before calling schemeForm.resetForm() to
avoid runtime errors if the ViewChild wasn't initialized: check that the
ViewChild property (schemeForm) is truthy (e.g., if (this.schemeForm) ...)
before invoking resetForm(); apply the same defensive check at the other
occurrence (around line with the second resetForm call) so both calls safely
handle a missing form reference.
src/app/sio-blood-on-call-service/sio-blood-on-call-service.component.ts (1)

618-619: ⚡ Quick win

Defensive null-checks on resetForm() calls are good practice but the stated concern about step-based conditional existence is not supported.

Both patientDetailsForm and hospitalDetailForm are always rendered together within *ngIf="showBloodRequestForm" in the template. They do not conditionally exist at different times—when one is present in the DOM, so is the other. The forms' content is controlled via [hidden] flags, not conditional rendering, so both remain available to ViewChild when the parent container is rendered.

That said, adding null-checks before resetForm() remains valid defensive programming:

+      if (this.hospitalDetailForm) {
+        this.hospitalDetailForm.resetForm();
+      }
+      if (this.patientDetailsForm) {
+        this.patientDetailsForm.resetForm();
+      }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/sio-blood-on-call-service/sio-blood-on-call-service.component.ts`
around lines 618 - 619, Add defensive null-checks before calling resetForm on
the form ViewChilds: ensure this.hospitalDetailForm and this.patientDetailsForm
are truthy before invoking their resetForm() methods (e.g., guard each call with
if (this.hospitalDetailForm) and if (this.patientDetailsForm)). This keeps
existing behavior (they are typically rendered together under
showBloodRequestForm) but prevents runtime errors if either ViewChild is
unexpectedly undefined during component lifecycle.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/app/beneficiary-registration-104/beneficiary-registration-104.component.ts`:
- Around line 1613-1616: Reorder and guard the form reset: call
registrationForm.resetForm() first (with a null/undefined check on
registrationForm) before setting showForm = false, then set personIsSelf =
false; this ensures the template-controlled form exists when reset is invoked
and mirrors the correct pattern used elsewhere (use the existing
registrationForm reference and the showForm and personIsSelf flags).

In
`@src/app/sio-epidemic-outbreak-service/sio-epidemic-outbreak-service.component.ts`:
- Around line 382-385: The code sets this.showTable = true before calling
this.epidemicForm.resetForm(), which causes the ViewChild epidemicForm to be
removed by *ngIf and become undefined; move the reset call to run before
toggling visibility (i.e., call this.epidemicForm.resetForm() prior to setting
this.showTable = true) and add a defensive null/undefined check on epidemicForm
before calling resetForm() to avoid a TypeError (referencing epidemicForm and
showTable in sio-epidemic-outbreak-service.component.ts).

---

Nitpick comments:
In `@src/app/multi-role-screen/multi-role-screen.component.ts`:
- Around line 134-138: The visibility check for showDbLabel relies on the
display string "Role Selection" which is fragile; update the component to use a
stable status key/enum from sendHeaderStatus instead: change the
sendHeaderStatus payload to include a status identifier (e.g.,
HeaderStatus.RoleSelection) and in multi-role-screen.component.ts replace the
string comparison with a check against that identifier (e.g., compare
data.status or the enum value), then set this.showDbLabel based on the stable
status key rather than the localized header text.

In `@src/app/sio-blood-on-call-service/sio-blood-on-call-service.component.ts`:
- Around line 618-619: Add defensive null-checks before calling resetForm on the
form ViewChilds: ensure this.hospitalDetailForm and this.patientDetailsForm are
truthy before invoking their resetForm() methods (e.g., guard each call with if
(this.hospitalDetailForm) and if (this.patientDetailsForm)). This keeps existing
behavior (they are typically rendered together under showBloodRequestForm) but
prevents runtime errors if either ViewChild is unexpectedly undefined during
component lifecycle.

In `@src/app/supervisor-upload-schemes/supervisor-uploadSchemes.component.ts`:
- Line 246: Add a null/undefined guard before calling schemeForm.resetForm() to
avoid runtime errors if the ViewChild wasn't initialized: check that the
ViewChild property (schemeForm) is truthy (e.g., if (this.schemeForm) ...)
before invoking resetForm(); apply the same defensive check at the other
occurrence (around line with the second resetForm call) so both calls safely
handle a missing form reference.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9f3eabbe-b4f9-4ee0-822b-7b03af2df8a1

📥 Commits

Reviewing files that changed from the base of the PR and between df5db19 and 61f62b4.

📒 Files selected for processing (20)
  • src/app/104/104.component.ts
  • src/app/beneficiary-registration-104/beneficiary-registration-104.component.ts
  • src/app/bp-screening-component/bp-screening-component.ts
  • src/app/case-sheet/case-sheet.component.ts
  • src/app/covid-19/covid-19.component.ts
  • src/app/diabetic-screening-component/diabetic-screening-component.ts
  • src/app/directory-services/directory-services.component.ts
  • src/app/multi-role-screen/multi-role-screen.component.html
  • src/app/multi-role-screen/multi-role-screen.component.ts
  • src/app/outbound-search-records/outbound-search-records.component.ts
  • src/app/prescription/prescription.component.ts
  • src/app/service-role-selection/service-role-selection.component.ts
  • src/app/sio-blood-on-call-service/sio-blood-on-call-service.component.ts
  • src/app/sio-epidemic-outbreak-service/sio-epidemic-outbreak-service.component.ts
  • src/app/sio-food-safety-service/sio-food-safety-service.component.ts
  • src/app/sio-grievience-service/sio-grievience-service.component.ts
  • src/app/sio-organ-donation-service/sio-organ-donation-service.component.ts
  • src/app/sio-outbound-provider/sio-outbound-provider.component.ts
  • src/app/sio-services/sio-services.component.ts
  • src/app/supervisor-upload-schemes/supervisor-uploadSchemes.component.ts
💤 Files with no reviewable changes (10)
  • src/app/prescription/prescription.component.ts
  • src/app/service-role-selection/service-role-selection.component.ts
  • src/app/sio-services/sio-services.component.ts
  • src/app/directory-services/directory-services.component.ts
  • src/app/outbound-search-records/outbound-search-records.component.ts
  • src/app/sio-organ-donation-service/sio-organ-donation-service.component.ts
  • src/app/104/104.component.ts
  • src/app/diabetic-screening-component/diabetic-screening-component.ts
  • src/app/bp-screening-component/bp-screening-component.ts
  • src/app/sio-food-safety-service/sio-food-safety-service.component.ts

Comment on lines 1613 to 1616
this.showForm = false;
//this.showTableFlag = true;
jQuery("#registerForm").trigger("reset");
this.registrationForm.resetForm();
this.personIsSelf = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify template conditional rendering and reset ordering.
rg -n -C3 'registrationForm|showForm|\*ngIf' \
  src/app/beneficiary-registration-104/beneficiary-registration-104.component.ts \
  src/app/beneficiary-registration-104/beneficiary-registration-104.component.html

Repository: PSMRI/Helpline104-UI

Length of output: 39041


Reorder form reset before hiding and add null-check for safety.

Line 1613–1615 hides the form via showForm = false before calling registrationForm.resetForm(). Since the form is guarded by *ngIf="showForm" in the template, this pattern is backwards and semantically incorrect. Additionally, if showForm is already false when this code path executes, registrationForm will be undefined.

The codebase already demonstrates the correct pattern elsewhere (line 1685): reset the form first, then hide it. Add a null-check for defensive safety.

Suggested fix
-    this.showForm = false;
-    //this.showTableFlag = true;
-    this.registrationForm.resetForm();
+    if (this.registrationForm) {
+      this.registrationForm.resetForm();
+    }
+    this.showForm = false;
+    //this.showTableFlag = true;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.showForm = false;
//this.showTableFlag = true;
jQuery("#registerForm").trigger("reset");
this.registrationForm.resetForm();
this.personIsSelf = false;
if (this.registrationForm) {
this.registrationForm.resetForm();
}
this.showForm = false;
//this.showTableFlag = true;
this.personIsSelf = false;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/app/beneficiary-registration-104/beneficiary-registration-104.component.ts`
around lines 1613 - 1616, Reorder and guard the form reset: call
registrationForm.resetForm() first (with a null/undefined check on
registrationForm) before setting showForm = false, then set personIsSelf =
false; this ensures the template-controlled form exists when reset is invoked
and mirrors the correct pattern used elsewhere (use the existing
registrationForm reference and the showForm and personIsSelf flags).

Comment on lines 382 to 385
this.showTable = true;
// this.showEpidemicForm = false;
jQuery("#epidemic_form").trigger("reset");
this.epidemicForm.resetForm();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether epidemic form is conditionally rendered with showTable.
rg -n -C3 'epidemic_Details_Form|epidemicForm|showTable|\*ngIf' \
  src/app/sio-epidemic-outbreak-service/sio-epidemic-outbreak-service.component.ts \
  src/app/sio-epidemic-outbreak-service/sio-epidemic-outbreak-service.component.html

Repository: PSMRI/Helpline104-UI

Length of output: 16934


🏁 Script executed:

rg -n 'epidemicForm' src/app/sio-epidemic-outbreak-service/sio-epidemic-outbreak-service.component.ts

Repository: PSMRI/Helpline104-UI

Length of output: 170


Reset form before hiding it to prevent undefined ViewChild reference.

The form template is conditionally rendered with *ngIf="!showTable" (line 1 of HTML). When this.showTable = true executes, Angular's change detection removes the form element from the DOM, making the epidemicForm ViewChild undefined. The subsequent resetForm() call on line 384 will throw a TypeError.

Reorder to reset the form before changing visibility:

Suggested fix
+        if (this.epidemicForm) {
+          this.epidemicForm.resetForm();
+        }
         this.showTable = true;
         //	this.showEpidemicForm = false;
-        this.epidemicForm.resetForm();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.showTable = true;
// this.showEpidemicForm = false;
jQuery("#epidemic_form").trigger("reset");
this.epidemicForm.resetForm();
}
if (this.epidemicForm) {
this.epidemicForm.resetForm();
}
this.showTable = true;
// this.showEpidemicForm = false;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/app/sio-epidemic-outbreak-service/sio-epidemic-outbreak-service.component.ts`
around lines 382 - 385, The code sets this.showTable = true before calling
this.epidemicForm.resetForm(), which causes the ViewChild epidemicForm to be
removed by *ngIf and become undefined; move the reset call to run before
toggling visibility (i.e., call this.epidemicForm.resetForm() prior to setting
this.showTable = true) and add a defensive null/undefined check on epidemicForm
before calling resetForm() to avoid a TypeError (referencing epidemicForm and
showTable in sio-epidemic-outbreak-service.component.ts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant