Skip to content

Commit b4e9efc

Browse files
committed
Fix: prevent empty and duplicate tags & show inline validation messages
1 parent 9a0929a commit b4e9efc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/app/modules/detailRoute/views/tags_widget.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,17 @@ class TagsRouteState extends State<TagsRoute> {
234234
color: tColors.primaryTextColor,
235235
),
236236
validator: (value) {
237-
if (value != null) {
238-
if (value.isNotEmpty && value.contains(" ")) {
239-
return "Tags cannot contain spaces";
240-
}
237+
if (value == null || value.trim().isEmpty) {
238+
return "Please enter a tag";
239+
}
240+
final tag = value.trim();
241+
if (tag.contains(" ")) {
242+
return "Tags cannot contain spaces";
243+
}
244+
final currentTags =
245+
draftTags?.build().toList() ?? <String>[];
246+
if (currentTags.contains(tag)) {
247+
return "Tag already exists";
241248
}
242249
return null;
243250
},

0 commit comments

Comments
 (0)