Reverted the semantic value from textfield#708
Reverted the semantic value from textfield#708SachinPremkumar wants to merge 1 commit intomosip:developfrom
Conversation
Signed-off-by: sachin.sp <sachin.sp@cyberpwn.com>
WalkthroughTwo 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
lib/ui/process_ui/widgets/pre_reg_data_control.dartlib/ui/process_ui/widgets/textbox_control.dart
| 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; |
There was a problem hiding this comment.
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.
| 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); | ||
| }, |
There was a problem hiding this comment.
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.
Summary by CodeRabbit