Skip to content

Add real-time underline validation, Enter key validation, and sync error border with toast for organization input#582

Open
gurusatsangi wants to merge 4 commits intofossasia:mainfrom
gurusatsangi:org-validation
Open

Add real-time underline validation, Enter key validation, and sync error border with toast for organization input#582
gurusatsangi wants to merge 4 commits intofossasia:mainfrom
gurusatsangi:org-validation

Conversation

@gurusatsangi
Copy link
Copy Markdown
Contributor

@gurusatsangi gurusatsangi commented Apr 20, 2026

📌 Fixes #581

📝 Summary of Changes

  • Added real-time underline validation during typing (debounced, format-based)
  • Enabled validation on Enter key press (same as blur behavior)
  • Synced red border with toast notification for invalid organization
  • Ensured red border persists until the input becomes valid
  • Removed border when:
    • Organization becomes valid
    • Input field is cleared

⚙️ Behavior Changes

  • Typing invalid format → underline shown
  • Pressing Enter → triggers validation (same as blur)
  • Invalid organization → toast + red border
  • Toast disappears → border remains (persistent feedback)
  • Valid organization → no toast + no border

📸screenshot

image

📸recording

2026-04-20.21-46-59.-.Trim.mp4

Before:

  • Validation only on blur
  • No Enter key support
  • No persistent visual feedback

After:

  • Real-time underline validation
  • Enter key triggers validation
  • Toast + persistent red border

✅ Checklist

  • I’ve tested my changes locally
  • I’ve added tests (if applicable)
  • I’ve updated documentation (if applicable)
  • My code follows the project’s code style guidelines

👀 Reviewer Notes

This PR improves UX by:

  • Providing real-time feedback during typing
  • Supporting Enter key validation
  • Adding persistent visual error indication
  • Ensuring consistency between toast and input state
  • Avoiding unnecessary API calls during typing

🔍 Summary by Sourcery

Enhance organization input validation by adding real-time feedback, enabling Enter key validation, and synchronizing error indication with toast and persistent border.

Summary by Sourcery

Improve organization input validation UX with real-time format feedback, Enter-key-triggered validation, and synchronized visual error indication.

New Features:

  • Add debounced real-time format validation for the organization input while typing.
  • Trigger organization validation when the Enter key is pressed, reusing blur behavior.

Enhancements:

  • Synchronize a persistent red error border on the organization input with toast-based validation results.
  • Clear the error border when the organization becomes valid or the input is emptied.

…ror border with toast for organization input
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 20, 2026

Reviewer's Guide

Implements real-time, format-based validation for the organization input, adds Enter-key-triggered validation that reuses existing blur logic, and synchronizes a persistent red error border with the invalid-organization toast using a shared CSS class.

Sequence diagram for real-time and Enter-key organization validation

sequenceDiagram
  actor User
  participant OrgInput as orgInput
  participant DebouncedValidator as debouncedValidateOrg
  participant BlurValidator as validateOrgOnBlur
  participant Fetch as validateOrganization
  participant GitHubAPI
  participant Toast as invalidOrgToast

  User->>OrgInput: Type characters
  OrgInput->>OrgInput: Persist orgName to storage
  OrgInput->>DebouncedValidator: input event (org)
  DebouncedValidator->>DebouncedValidator: Check format /^[a-z0-9-]{1,39}$/
  alt Invalid format
    DebouncedValidator->>OrgInput: Add class invalid-org
  else Valid format or empty
    DebouncedValidator->>OrgInput: Remove class invalid-org
  end

  User->>OrgInput: Press Enter
  OrgInput->>OrgInput: keydown Enter (prevent default)
  OrgInput->>OrgInput: blur()
  OrgInput->>BlurValidator: validateOrgOnBlur(org)
  BlurValidator->>Fetch: validateOrganization(org)
  Fetch->>GitHubAPI: GET /orgs/{org}
  GitHubAPI-->>Fetch: HTTP status
  alt Status 200
    BlurValidator->>Toast: Remove existing invalid-org-toast
    BlurValidator->>OrgInput: Remove class invalid-org
  else Non-200 or error
    BlurValidator->>Toast: Create invalid-org-toast element
    BlurValidator->>OrgInput: Add class invalid-org
    Toast-->>Toast: Auto-remove after timeout
  end
Loading

Flow diagram for organization input CSS border and toast state

flowchart TD
  A["User types in orgInput"] --> B["Persist orgName to storage"]
  B --> C{"Debounced format check<br>/^[a-z0-9-]{1,39}$/"}
  C -->|Empty input| D["Remove class invalid-org"]
  C -->|Invalid format| E["Add class invalid-org (underline)"]
  C -->|Valid format| F["Remove class invalid-org"]

  G["User presses Enter or input blurs"] --> H["Call validateOrgOnBlur(org)"]
  H --> I["Call validateOrganization(org)"]
  I --> J{"GitHub API status"}
  J -->|200 OK| K["Remove invalid-org-toast if present"]
  K --> L["Remove class invalid-org (no error)"]
  J -->|Non-200 or error| M["Show invalid-org-toast"]
  M --> N["Add class invalid-org (red border)"]
  M --> O["Toast auto-dismiss after timeout"]
  O --> P["Red border remains until org becomes valid or input cleared"]
Loading

File-Level Changes

Change Details Files
Add debounced, format-only validation while typing in the organization input and persist the normalized value to storage.
  • Introduce a debounced validation function that checks the organization string against a GitHub-compatible regex and toggles the invalid state accordingly without calling the API.
  • Normalize input to trimmed, lowercase text on each input event and immediately save it to browser storage.
  • Ensure clearing the input removes any invalid styling.
src/scripts/popup.js
Make Enter key trigger the same validation flow as blur for the organization input.
  • Add a keydown listener on the organization input that intercepts Enter, prevents default form submission, and programmatically blurs the field to trigger existing validation.
  • Reuse the blur handler so Enter produces the same toast and border behavior as leaving the field.
src/scripts/popup.js
Synchronize a persistent red border with invalid-organization toast state via a shared CSS class.
  • Add a reusable .invalid-org CSS class that applies a red border to the organization input.
  • Set the invalid-org class when the organization is not found or when there is a validation error, in parallel with showing the toast.
  • Remove the invalid-org class when the organization validates successfully or the input becomes empty, independent of toast lifetime.
src/scripts/popup.js
src/index.css

Assessment against linked issues

Issue Objective Addressed Explanation
#581 Add debounced, real-time organization format validation while typing, using underline feedback without API calls.
#581 Trigger final organization validation on both blur and Enter key press, using the GitHub API to verify organization existence.
#581 Show toast + red border for invalid organizations on final validation, and keep the red border visible (and cleared) in sync with validity and input clearing.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions Bot added javascript Pull requests that update javascript code frontend labels Apr 20, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 3 issues, and left some high level feedback:

  • The new validateOrganization async helper is never used; either wire it into the validation flow (e.g., for blur/Enter validation) or remove it to avoid dead code.
  • Consider deferring browser.storage.local.set({ orgName: org }) to blur/Enter or throttling it, since updating storage on every input event can be unnecessarily frequent for fast typing.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `validateOrganization` async helper is never used; either wire it into the validation flow (e.g., for blur/Enter validation) or remove it to avoid dead code.
- Consider deferring `browser.storage.local.set({ orgName: org })` to blur/Enter or throttling it, since updating storage on every `input` event can be unnecessarily frequent for fast typing.

## Individual Comments

### Comment 1
<location path="src/scripts/popup.js" line_range="882" />
<code_context>
+				return;
+			}
+
+			const isValidFormat = /^[a-z0-9-]{1,39}$/.test(org);
+
+			if (!isValidFormat) {
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Org name regex is permissive in ways GitHub is not (leading/trailing hyphens, consecutive hyphens) and may give misleading feedback.

GitHub org names can’t start or end with a hyphen and can’t contain consecutive hyphens, but this pattern allows them (e.g. `-foo`, `foo-`, `foo--bar`). Those values will be treated as “valid format” here and then rejected by the API, leading to confusing UX. Please either tighten the regex to match GitHub’s rules or centralize the validation so UI and API stay aligned.

```suggestion
			// GitHub org rules: 1–39 chars, lowercase letters/digits/hyphens,
			// no leading/trailing hyphen, no consecutive hyphens
			const isValidFormat = /^(?!.*--)[a-z0-9](?:[a-z0-9-]{0,37}[a-z0-9])?$/.test(org);
```
</issue_to_address>

### Comment 2
<location path="src/scripts/popup.js" line_range="895" />
<code_context>
+		orgInput.addEventListener('input', () => {
+			const org = orgInput.value.trim().toLowerCase();
+
+			browser.storage.local.set({ orgName: org });
+
+			debouncedValidateOrg(org);
</code_context>
<issue_to_address>
**suggestion (performance):** Writing to browser.storage on every keystroke can be unnecessarily heavy; consider debouncing or deferring.

Since `input` fires on every keypress, this will trigger a storage write per character, which may be excessive for frequent use. You could either reuse the existing debounce (so writes happen only after the user pauses), or only persist on blur/Enter when editing is finished, preserving behavior while reducing I/O.

Suggested implementation:

```javascript
			}
		}, 500);

		const debouncedSaveOrgName = debounce((org) => {
			browser.storage.local.set({ orgName: org });
		}, 500);

		// 🔹 INPUT (typing + backspace both covered)
		orgInput.addEventListener('input', () => {
			const org = orgInput.value.trim().toLowerCase();

			debouncedSaveOrgName(org);
			debouncedValidateOrg(org);
		});

```

If the debounce delay for validation and storage should differ (e.g., faster validation vs. slower writes), you may want to adjust the `500` ms timeout for `debouncedSaveOrgName` independently, or derive it from a shared constant used elsewhere in the file.
</issue_to_address>

### Comment 3
<location path="src/index.css" line_range="403-405" />
<code_context>
     }
 }
-
+.invalid-org {
+	border: 1px solid #ef4444 !important;
+}
 @keyframes shake {
</code_context>
<issue_to_address>
**suggestion:** Using `!important` on `.invalid-org` could make it hard to integrate with existing theming or focus styles.

Because this sets a full border with `!important`, it can override focus rings, themed borders, or high-contrast styles on the same element. If you just need to show an error, consider changing only the border color (without `!important` if you can), or narrowing the selector to the specific input. That keeps it compatible with other states like focus and hover.

```suggestion
.invalid-org {
	border-color: #ef4444;
}
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/scripts/popup.js Outdated
Comment thread src/scripts/popup.js Outdated
Comment thread src/index.css
gurusatsangi and others added 3 commits April 20, 2026 22:11
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]: Improve organization input validation with real-time feedback, Enter key support, and persistent error indication

1 participant