From af42e18f6e0619ced390dd26b77603e857f33a30 Mon Sep 17 00:00:00 2001 From: Doug Borg Date: Tue, 10 Feb 2026 18:56:28 -0700 Subject: [PATCH] Guard onFieldSubmitted on non-empty text to prevent cleared values reappearing When a user clears a tag value and presses Done, RawAutocomplete's onFieldSubmitted auto-selects the first option from the suggestions list. Since optionsBuilder returns all suggestions for empty text, this causes the cleared value to reappear. Guarding the call on non-empty text prevents the auto-selection while preserving autocomplete behavior when the user has typed a partial match. Co-Authored-By: Claude Opus 4.6 --- lib/widgets/nsi_tag_value_field.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/widgets/nsi_tag_value_field.dart b/lib/widgets/nsi_tag_value_field.dart index 51685f1..d05f752 100644 --- a/lib/widgets/nsi_tag_value_field.dart +++ b/lib/widgets/nsi_tag_value_field.dart @@ -132,7 +132,14 @@ class _NSITagValueFieldState extends State { onChanged: (value) { widget.onChanged(value); }, - onSubmitted: (_) => onFieldSubmitted(), + onSubmitted: (_) { + // Only auto-complete when there's text to match against. + // Otherwise, pressing Done on an empty field would auto-select + // the first suggestion, preventing users from clearing values. + if (controller.text.isNotEmpty) { + onFieldSubmitted(); + } + }, ); }, optionsViewBuilder: (