Skip to content

Reverted the semantic value from textfield#708

Open
SachinPremkumar wants to merge 1 commit intomosip:developfrom
SachinPremkumar:UI-ID
Open

Reverted the semantic value from textfield#708
SachinPremkumar wants to merge 1 commit intomosip:developfrom
SachinPremkumar:UI-ID

Conversation

@SachinPremkumar
Copy link
Collaborator

@SachinPremkumar SachinPremkumar commented Mar 12, 2026

Summary by CodeRabbit

  • Refactor
    • Refactored and optimized form field components and their validation mechanisms to enhance code maintainability, quality, and organization. All existing application functionality, form behavior, input validation workflows, and user interface experience remain completely unchanged by these internal improvements.

Signed-off-by: sachin.sp <sachin.sp@cyberpwn.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2026

Walkthrough

Two UI widget files are modified to restructure form field implementations. The first removes a Semantics wrapper from a TextFormField while preserving identical behavior. The second replaces a Semantics-wrapped field with a plain Container, removes raw value persistence on input change, and introduces a dedicated validator function.

Changes

Cohort / File(s) Summary
Form Field Wrapper Restructuring
lib/ui/process_ui/widgets/pre_reg_data_control.dart
Removed Semantics wrapper around application_id TextFormField; keyboard behavior, controller, validators, and decoration remain unchanged.
Text Input Control Refactoring
lib/ui/process_ui/widgets/textbox_control.dart
Replaced Semantics-wrapped TextFormField with plain Container; removed raw input persistence on onChanged for non-transliteration paths; moved validation logic to dedicated validator function; transliteration flow retained without persisting original input value.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through widget lanes,
Removing wrappers, breaking chains,
Semantics fade, but forms stay true,
Validation flows with validators new,
Cleaner code, a simpler view! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Reverted the semantic value from textfield' accurately reflects the main changes: removal of Semantics wrappers from TextFormField widgets in both modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/ui/process_ui/widgets/pre_reg_data_control.dart`:
- Around line 262-269: The validator for the ID field currently only checks for
length > pridLength and lets short or non-numeric values pass; update the
validator closure in pre_reg_data_control.dart (the validator used in the widget
at/around the validator: (value) { ... } block) to enforce exact-length and
numeric-only rules: if globalProvider.pridLength is set, require value.length ==
globalProvider.pridLength and that value matches a digits-only pattern (e.g.,
regex for exactly N digits); return the existing localized error message (or a
new localized message) when the value fails these checks and return null only
when it exactly matches the required digit count. Ensure you reference
globalProvider.pridLength and AppLocalizations in the updated validator.

In `@lib/ui/process_ui/widgets/textbox_control.dart`:
- Around line 176-204: The onChanged handler launches async transliteration for
each target and directly writes awaited results into controllerMap and saves
them, allowing stale responses to overwrite newer input; fix by introducing a
per-input request token or incrementing requestId (scoped to this widget) before
calling TransliterationServiceImpl().transliterate and, after awaiting, verify
the token/requestId still matches the latest value before calling
_saveDataToMap, saveData, or updating controllerMap[targetCode]!.text; reference
the onChanged closure, TransliterationServiceImpl().transliterate call,
controllerMap[targetCode]!.text updates, and _saveDataToMap/saveData calls to
add this guard so only the most recent transliteration result is applied.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 40f342b2-be2f-46f9-afff-2370c7be449f

📥 Commits

Reviewing files that changed from the base of the PR and between c24051c and f72a152.

📒 Files selected for processing (2)
  • lib/ui/process_ui/widgets/pre_reg_data_control.dart
  • lib/ui/process_ui/widgets/textbox_control.dart

Comment on lines +262 to +269
validator: (value) {
if (value == null || value.isEmpty) return null;
if (globalProvider.pridLength != null &&
value.length > globalProvider.pridLength!) {
return AppLocalizations.of(context)!
.prid_length_greater(globalProvider.pridLength!);
}
return null;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Make the field validator match the fetch-time rules.

This validator only rejects values longer than pridLength. Short or non-numeric IDs still pass validate(), so the fetch handler proceeds into the invalid-ID branch and its side effects. Mirror the exact-length + digits check here.

Possible fix
                 validator: (value) {
                   if (value == null || value.isEmpty) return null;
-                  if (globalProvider.pridLength != null &&
-                      value.length > globalProvider.pridLength!) {
-                    return AppLocalizations.of(context)!
-                        .prid_length_greater(globalProvider.pridLength!);
+                  final pridLength = globalProvider.pridLength;
+                  if (pridLength != null &&
+                      (value.length != pridLength ||
+                          !RegExp(r'^\d+$').hasMatch(value))) {
+                    return AppLocalizations.of(context)!.correct_application_id;
                   }
                   return null;
                 },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/ui/process_ui/widgets/pre_reg_data_control.dart` around lines 262 - 269,
The validator for the ID field currently only checks for length > pridLength and
lets short or non-numeric values pass; update the validator closure in
pre_reg_data_control.dart (the validator used in the widget at/around the
validator: (value) { ... } block) to enforce exact-length and numeric-only
rules: if globalProvider.pridLength is set, require value.length ==
globalProvider.pridLength and that value matches a digits-only pattern (e.g.,
regex for exactly N digits); return the existing localized error message (or a
new localized message) when the value fails these checks and return null only
when it exactly matches the required digit count. Ensure you reference
globalProvider.pridLength and AppLocalizations in the updated validator.

Comment on lines +176 to +204
onChanged: (value) async {
if (lang == mandatoryLanguageCode) {
for (var target in choosenLang) {
String targetCode = globalProvider.langToCode(target);
if (targetCode != mandatoryLanguageCode) {
log("$mandatoryLanguageCode ----> $targetCode");
try {
String result = await TransliterationServiceImpl()
.transliterate(TransliterationOptions(
input: value,
sourceLanguage: "Any",
targetLanguage: tranliterationLangMapper[
targetCode] ??
targetCode.substring(0, 2)));
_saveDataToMap(result, targetCode);
saveData(result, targetCode);
setState(() {
controllerMap[targetCode]!.text = result;
});
log("Transliteration success : $result");
} catch (e) {
log("Transliteration failed : $e");
}
}
}
_saveDataToMap(value, lang);
saveData(value, lang);
},
validator: (value) {
if (!widget.e.required!) {
if (widget.e.requiredOn == null ||
widget.e.requiredOn!.isEmpty ||
!(globalProvider.mvelRequiredFields[widget.e.id] ??
true)) {
if (value == null || value.isEmpty) {
return null;
} else if (!widget.validation.hasMatch(value)) {
return AppLocalizations.of(context)!.invalid_input;
}
}
_saveDataToMap(value, lang);
saveData(value, lang);
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Ignore stale transliteration responses.

Each keystroke starts async transliteration work and then blindly writes the awaited result into the target controllers. If an older request finishes last, it can overwrite newer input and persist stale demographics.

Possible fix
 class _TextBoxControlState extends State<TextBoxControl>
     with WidgetsBindingObserver {
   bool isMvelValid = true;
   Map<String, TextEditingController> controllerMap = {};
   late GlobalProvider globalProvider;
   late RegistrationTaskProvider registrationTaskProvider;
+  int _transliterationRequestId = 0;
@@
                   onChanged: (value) async {
+                    final requestId = ++_transliterationRequestId;
                     if (lang == mandatoryLanguageCode) {
                       for (var target in choosenLang) {
                         String targetCode = globalProvider.langToCode(target);
                         if (targetCode != mandatoryLanguageCode) {
@@
                             String result = await TransliterationServiceImpl()
                                 .transliterate(TransliterationOptions(
                                     input: value,
                                     sourceLanguage: "Any",
                                     targetLanguage: tranliterationLangMapper[
                                             targetCode] ??
                                         targetCode.substring(0, 2)));
+                            if (!mounted ||
+                                requestId != _transliterationRequestId ||
+                                controllerMap[lang]?.text != value) {
+                              continue;
+                            }
                             _saveDataToMap(result, targetCode);
                             saveData(result, targetCode);
                             setState(() {
                               controllerMap[targetCode]!.text = result;
                             });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/ui/process_ui/widgets/textbox_control.dart` around lines 176 - 204, The
onChanged handler launches async transliteration for each target and directly
writes awaited results into controllerMap and saves them, allowing stale
responses to overwrite newer input; fix by introducing a per-input request token
or incrementing requestId (scoped to this widget) before calling
TransliterationServiceImpl().transliterate and, after awaiting, verify the
token/requestId still matches the latest value before calling _saveDataToMap,
saveData, or updating controllerMap[targetCode]!.text; reference the onChanged
closure, TransliterationServiceImpl().transliterate call,
controllerMap[targetCode]!.text updates, and _saveDataToMap/saveData calls to
add this guard so only the most recent transliteration result is applied.

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