Skip to content

[ES-2857] [ES-2952] [#1812] [#1803] UI validation and other fixes.#153

Merged
zesu22 merged 4 commits into
mosip:developfrom
gk-XL7:ES-2857
May 21, 2026
Merged

[ES-2857] [ES-2952] [#1812] [#1803] UI validation and other fixes.#153
zesu22 merged 4 commits into
mosip:developfrom
gk-XL7:ES-2857

Conversation

@gk-XL7
Copy link
Copy Markdown
Contributor

@gk-XL7 gk-XL7 commented May 11, 2026

Summary by CodeRabbit

  • Chores

    • Package version released: 0.1.1-beta.9
  • Bug Fixes

    • Dropdowns become required when related file uploads exist; validation and placeholder behavior improved.
    • File upload validation unified and consistently applied during selection, upload, and deletion; required-state handling fixed.
    • Language updates now refresh and revalidate all fields to ensure consistent UI state.
    • Regex/locale-aware validation improved for password, phone, text, and textarea inputs.
  • Style

    • ReCAPTCHA and file-upload spacing/layout adjusted for better responsiveness.

Review Change Stack

… support for deselect option from dropdown.

Signed-off-by: GurukiranP <talk2gurukiran@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Walkthrough

Bumps package version; centralizes file-required validation in validateFileField(), makes dropdowns conditionally required when related uploads exist, propagates language context to regex validators, triggers events for all fields on language change, and adjusts minor UI/CSS and wrapper dataset attributes.

Changes

Form Validation Integration for File Upload and Dropdown Components

Layer / File(s) Summary
Package Version Update
json-form-builder/package.json
Version bumped from 0.1.1-beta.8 to 0.1.1-beta.9.
Dropdown: Add FileUploadData Import
json-form-builder/src/components/DropdownComponent.ts
Import FileUploadData to enable dropdown validation to inspect parent file upload data.
Dropdown UI Refinements
json-form-builder/src/components/DropdownComponent.ts
Placeholder option no longer forced disabled/selected/hidden; unmatched prefilled values reset to ""; change handler normalizes empty values, updates styling, and re-validates; native customValidity removed.
Dropdown Parent Field Integration
json-form-builder/src/components/DropdownComponent.ts
validateSelect computes parent upload id (strip _docType) and treats dropdown as required when parent upload has value; toggles "error" CSS class.
File Upload: DocType Wiring & Field Definitions
json-form-builder/src/components/FileUploadComponent.ts
Remove label.htmlFor, stop spreading parent field into docType dropdown, ensure proof-of-document textbox sets id/controlType, and persist fileData.docType in docType change handler.
File Upload: validateFileField() & Event Dispatch
json-form-builder/src/components/FileUploadComponent.ts
New validateFileField() computes requiredness as `field.required
Regex Validation Language Context & Wrapper IDs
json-form-builder/src/components/*
Password, phone, text, and textarea components pass state.currentLanguage into handleRegexValidation; some wrappers now set data-field-id.
Language Normalization and Full-field Event Trigger
json-form-builder/src/JsonFormBuilder.ts
updateLanguage prefers mapped language via state.languageMap[newLanguage] and triggers events for all fields after updating language/RTL/submission state.
Responsive UI Tweaks
json-form-builder/src/utils/responsive-style.ts
.recaptcha-container becomes centered flex with larger bottom margin; .file-upload .input_box bottom margin reduced to 0px.

Sequence Diagram

sequenceDiagram
  participant User as User
  participant DocType as DocType Select
  participant Upload as FileUploadComponent
  participant Validator as validateFileField
  participant Dropdown as DropdownComponent
  User->>Upload: upload file / delete file
  Upload->>Validator: update fileData (value/format) -> validateFileField()
  DocType->>Upload: change docType selection
  Upload->>Validator: set fileData.docType -> validateFileField()
  Validator->>DocType: dispatch "input" event
  Validator->>Dropdown: recompute required state -> toggle "error" class
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A tiny hop for version nine,
Uploads and dropdowns check in line,
Validator whispers, events take flight,
Regex learns the language right,
CSS snug, the form feels fine!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title references validation and fixes matching the changeset, but is overly broad and generic; it includes multiple issue numbers without conveying what was actually fixed. Consider a more specific title like 'Add validation for file uploads and dropdown deselection' that clearly describes the primary changes without relying on issue numbers.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
json-form-builder/src/components/FileUploadComponent.ts (1)

76-87: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Prefilled docType is not synced to parent file state.

At Line 79, docType is only copied on "change". Prefilled/default select values won’t trigger this event, so fileData.docType can remain empty and required-file validation can be skipped for optional file fields.

Suggested fix
 if (docTypeFieldEl) {
     const selectEl = (docTypeFieldEl as HTMLDivElement).querySelector("select");
+    const syncDocTypeToFileData = () => {
+        if (!selectEl) return;
+        state.formData[field.id] ??= {} as FileUploadData;
+        const fileData = state.formData[field.id] as FileUploadData;
+        fileData.docType = selectEl.value || "";
+    };

     selectEl?.addEventListener("change", () => {
-        state.formData[field.id] ??= {} as FileUploadData;
-
-        const fileData = state.formData[field.id] as FileUploadData;
-        fileData.docType = selectEl.value;
+        syncDocTypeToFileData();

         // validate file field immediately
         validateFileField();
     });
+
+    // keep parent state in sync with prefilled/default dropdown value
+    syncDocTypeToFileData();
 }
🤖 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 `@json-form-builder/src/components/FileUploadComponent.ts` around lines 76 -
87, The prefilled select value isn't synced because you only set
fileData.docType inside the select "change" handler; update the code so when you
obtain docTypeFieldEl/selectEl you also ensure state.formData[field.id] is
initialized (as FileUploadData) and immediately assign fileData.docType =
selectEl.value, then keep the existing change listener to update on user edits
and call validateFileField() after the immediate assignment to ensure validation
runs for prefilled values (references: docTypeFieldEl, selectEl,
state.formData[field.id], FileUploadData, validateFileField).
🤖 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 `@json-form-builder/src/components/FileUploadComponent.ts`:
- Line 295: The code assigns to state.lastErrors![field.id] without ensuring
state.lastErrors exists; initialize it before writing to avoid runtime
exceptions. Update the logic around the assignment (the block that sets
lastError for a field) to check if state.lastErrors is falsy and create an empty
object (with the correct typed shape) first, then assign
state.lastErrors[field.id] = lastError; keep the existing field.id and lastError
variables and preserve types when initializing.

---

Outside diff comments:
In `@json-form-builder/src/components/FileUploadComponent.ts`:
- Around line 76-87: The prefilled select value isn't synced because you only
set fileData.docType inside the select "change" handler; update the code so when
you obtain docTypeFieldEl/selectEl you also ensure state.formData[field.id] is
initialized (as FileUploadData) and immediately assign fileData.docType =
selectEl.value, then keep the existing change listener to update on user edits
and call validateFileField() after the immediate assignment to ensure validation
runs for prefilled values (references: docTypeFieldEl, selectEl,
state.formData[field.id], FileUploadData, validateFileField).
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 598bc9ca-27b9-4950-8733-8485b893e254

📥 Commits

Reviewing files that changed from the base of the PR and between 74bdef4 and 0775f4a.

⛔ Files ignored due to path filters (1)
  • json-form-builder/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • json-form-builder/package.json
  • json-form-builder/src/components/DropdownComponent.ts
  • json-form-builder/src/components/FileUploadComponent.ts

Comment thread json-form-builder/src/components/FileUploadComponent.ts Outdated
Signed-off-by: GurukiranP <talk2gurukiran@gmail.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
json-form-builder/src/components/FileUploadComponent.ts (1)

308-317: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Initialize state.lastErrors before assignment (line 315).

Line 315 uses the non-null assertion operator (state.lastErrors![field.id]) without ensuring state.lastErrors is initialized. This is inconsistent with the fix applied at line 295 and will throw a runtime error if lastErrors is undefined.

🐛 Proposed fix
         if (shouldRequireFile && !file) {
             const result = handleRequiredValidation(state, errorContainer);
+            state.lastErrors ||= {};
             state.lastErrors![field.id] = result.lastError;
             return;
         }

Or use the same pattern as line 295-296 without the non-null assertion:

         if (shouldRequireFile && !file) {
             const result = handleRequiredValidation(state, errorContainer);
-            state.lastErrors![field.id] = result.lastError;
+            state.lastErrors ||= {};
+            state.lastErrors[field.id] = result.lastError;
             return;
         }
🤖 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 `@json-form-builder/src/components/FileUploadComponent.ts` around lines 308 -
317, The code assigns into state.lastErrors using a non-null assertion
(state.lastErrors![field.id]) without ensuring state.lastErrors is initialized;
before setting state.lastErrors[field.id] when shouldRequireFile is true (in the
validation block that uses file, shouldRequireFile, and
handleRequiredValidation), ensure state.lastErrors is an object (e.g. initialize
state.lastErrors = state.lastErrors ?? {} or otherwise guard so you don't use
the non-null assertion). Update the validation block to initialize or guard
state.lastErrors prior to assigning the result.lastError for field.id.
🤖 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.

Outside diff comments:
In `@json-form-builder/src/components/FileUploadComponent.ts`:
- Around line 308-317: The code assigns into state.lastErrors using a non-null
assertion (state.lastErrors![field.id]) without ensuring state.lastErrors is
initialized; before setting state.lastErrors[field.id] when shouldRequireFile is
true (in the validation block that uses file, shouldRequireFile, and
handleRequiredValidation), ensure state.lastErrors is an object (e.g. initialize
state.lastErrors = state.lastErrors ?? {} or otherwise guard so you don't use
the non-null assertion). Update the validation block to initialize or guard
state.lastErrors prior to assigning the result.lastError for field.id.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 58e01d6e-4263-4a5c-9639-50929e5805d9

📥 Commits

Reviewing files that changed from the base of the PR and between 0775f4a and 0ed376d.

📒 Files selected for processing (1)
  • json-form-builder/src/components/FileUploadComponent.ts

Signed-off-by: GurukiranP <talk2gurukiran@gmail.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@json-form-builder/src/components/DropdownComponent.ts`:
- Around line 108-111: Restore schema-level required validation by combining the
original field.required with the conditional upload/doc-type rule: compute the
effective required flag using field.required OR (isFileUploaded || hasDocType)
(or equivalent logic) and use that combined value where shouldBeRequired is
currently used (referencing shouldBeRequired, isFileUploaded, hasDocType,
select.value and field.required). Ensure the dropdown still fails validation
when field.required is true even if no file/upload flags are set, while also
remaining required when either isFileUploaded or hasDocType is true.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ab544008-7b04-4212-b74c-54e0714762f5

📥 Commits

Reviewing files that changed from the base of the PR and between 0ed376d and d66eb19.

📒 Files selected for processing (8)
  • json-form-builder/src/JsonFormBuilder.ts
  • json-form-builder/src/components/DropdownComponent.ts
  • json-form-builder/src/components/FileUploadComponent.ts
  • json-form-builder/src/components/PasswordComponent.ts
  • json-form-builder/src/components/PhoneInputComponent.ts
  • json-form-builder/src/components/TextInputComponent.ts
  • json-form-builder/src/components/TextareaComponent.ts
  • json-form-builder/src/utils/responsive-style.ts
💤 Files with no reviewable changes (1)
  • json-form-builder/src/components/FileUploadComponent.ts

Comment thread json-form-builder/src/components/DropdownComponent.ts Outdated
Signed-off-by: GurukiranP <talk2gurukiran@gmail.com>
@gk-XL7 gk-XL7 changed the title [ES-2857] Added validation for the file and photo upload and provided support for deselect option from dropdown. [ES-2857] [ES-2952] [#1812] [#1803] UI validation and other fixes. May 20, 2026
Copy link
Copy Markdown
Contributor

@zesu22 zesu22 left a comment

Choose a reason for hiding this comment

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

looks fine for me

@zesu22 zesu22 merged commit 0413b5b into mosip:develop May 21, 2026
9 of 10 checks passed
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.

2 participants