Skip to content

fix: Show red text if the tag already exists and disable the button#20368

Open
PrathamDevX wants to merge 2 commits intoankidroid:mainfrom
PrathamDevX:add-tag-validation
Open

fix: Show red text if the tag already exists and disable the button#20368
PrathamDevX wants to merge 2 commits intoankidroid:mainfrom
PrathamDevX:add-tag-validation

Conversation

@PrathamDevX
Copy link
Contributor

Purpose / Description

The PR fixes the issue where adding an already existing tag does not provide proper validation feedback.
Now the Add Tag dialog shows a red error message and disables the OK button when a duplicate tag is entered.

Fixes

Approach

Added validation in TagsDialog.kt to check whether the entered tag already exists.

  • Normalizes user input using TagsUtil.getUniformedTag()
  • Displays inline error text when a duplicate tag is detected
  • Disables the OK button until a valid unique tag is entered

How Has This Been Tested?

Ran the app and verified that when entering an existing tag in the Add Tag dialog, a red error message is displayed and the OK button remains disabled.

Also verified that entering a new unique tag enables the OK button and allows the tag to be added successfully.

before:
Screenshot From 2026-02-28 00-47-51

Screenshot From 2026-02-28 00-48-01

after:
image

Learning (optional, can help others)

None

Links to blog posts, patterns, libraries or addons used to solve this problem

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@welcome
Copy link

welcome bot commented Feb 27, 2026

First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible.

@github-actions
Copy link
Contributor

Important

Maintainers: This PR contains Strings changes

  1. Sync Translations before merging this PR and wait for the action to complete
  2. Review and merge the auto-generated PR in order to sync all user-submitted translations
  3. Sync Translations again and merge the PR so the huge automated string changes caused by merging this PR are by themselves and easy to review

Comment on lines 390 to 397

addTag(input.toString())
d?.dismiss()
}

val inputET = addTagDialog.getInputField()

inputET.filters = arrayOf(addTagFilter)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unwanted changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out.

Copy link
Contributor

Choose a reason for hiding this comment

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

The changes are not done yet

inputET.filters = arrayOf(addTagFilter)

if (!prefixTag.isNullOrEmpty()) {
// utilize the addTagFilter to append '::' properly by appending a space to prefixTag
Copy link
Contributor

Choose a reason for hiding this comment

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

Why removing the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, that wasn’t intentional. I’ll add it back.

Comment on lines +409 to +413
// SAFE WAY TO FIND TextInputLayout
val textInputLayout =
generateSequence(inputET.parent) { (it as? View)?.parent }
.filterIsInstance<com.google.android.material.textfield.TextInputLayout>()
.firstOrNull()
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this a safe way? Can you explain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used this approach to search up the view hierarchy for TextInputLayout instead of assuming a fixed parent. I called it “safe” in that sense, but I understand it still depends on the current layout structure. I can adjust the wording or simplify the approach if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve made the requested changes in the latest commit.

@criticalAY criticalAY added Needs Author Reply Waiting for a reply from the original author and removed Needs Review labels Feb 27, 2026
<string name="dyn_deck_desc">This is a special deck for studying outside of the normal schedule. Cards will be automatically returned to their original decks after you review them. Deleting this deck from the deck list will return all remaining cards to their original deck.</string>
<string name="tag_editor_add_feedback">Touch “%2$s” to confirm adding “%1$s”</string>
<string name="tag_editor_add_feedback_existing">Existing tag “%1$s” selected</string>
<string name="tag_already_exists">Tag "%1$s" already exists</string>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be generic doesn't need to have the tag name in the string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will change it to generic.

@PrathamDevX PrathamDevX requested a review from criticalAY March 1, 2026 07:08
Copy link
Contributor

@criticalAY criticalAY left a comment

Choose a reason for hiding this comment

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

Changes are not reverted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Author Reply Waiting for a reply from the original author Strings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants