Skip to content

feat(ai-create): show character counter under the AI prompt field - #127

Merged
paulocastellano merged 5 commits into
trypostit:mainfrom
dantaspaulo:feat/ai-prompt-char-counter
Jul 17, 2026
Merged

feat(ai-create): show character counter under the AI prompt field#127
paulocastellano merged 5 commits into
trypostit:mainfrom
dantaspaulo:feat/ai-prompt-char-counter

Conversation

@dantaspaulo

Copy link
Copy Markdown
Contributor

Problem

The AI post prompt is validated with max:2000 on the backend
(StartPostCreationRequest), but the create form gives no hint of that limit.
Users can type well past 2000 characters and only discover the cap through a
validation error when they hit generate.

Change

A live character counter below the "What is this post about?" textarea in
AiPostWizard.vue:

  • Shows length/2000, right-aligned under the field.
  • Turns red (text-destructive) once the prompt exceeds the limit.
  • The generate button is disabled while over the limit — canSubmit now also
    checks promptText.length <= PROMPT_MAX — so the limit is enforced in the UI
    before the request is sent.

PROMPT_MAX mirrors the backend max:2000 rule so the two stay in sync.

Frontend-only, single file: resources/js/components/posts/create/AiPostWizard.vue.

dantaspaulo and others added 5 commits July 1, 2026 01:22
The AI post prompt is validated with `max:2000` on the backend, but the
create form gave no hint of the limit — users could write past it and only
find out via a validation error on submit.

Add a live `X/2000` counter below the "What is this post about?" textarea.
It turns red (`text-destructive`) once the prompt exceeds the limit, and the
generate button is disabled while over it (`canSubmit` now checks
`length <= PROMPT_MAX`), so the limit is caught before the request.
The counter added earlier drifted from the backend in two ways: it counted
UTF-16 code units over the raw (untrimmed) value, while the backend measures
Unicode characters (mb_strlen) over the trimmed value that is actually sent —
so emoji or trailing whitespace could falsely turn the counter red and block
the button. The 2000 limit was also copied into three places, and the wizard's
frontend `>= 3` minimum had no backend counterpart.

- Add App\Support\AiPromptRules as the single source of truth for the prompt
  bounds; both StartPostCreationRequest and GeneratePostContentRequest use it.
- Add min:3 to the create wizard endpoint so front and back agree (the editor's
  generate-content flow keeps `required` — it has no counter to mirror).
- Count code points over the trimmed value in AiPostWizard so the counter and
  the submit gate match what the backend validates, matching AltTextDialog.
- Cover min/max/boundary in PostAiCreateTest.
…boundary

- Assert GeneratePostContentRequest rejects a prompt over the shared max, so the
  editor's limit is pinned explicitly (not only implied by the create wizard).
- Assert the create wizard accepts a prompt at exactly the minimum length,
  complementing the below-minimum rejection.
- Rename AiPromptRules::promptRule() to wizardPromptRule() so the asymmetry is
  explicit: only the create wizard carries a minimum; the editor's generation
  reuses just the shared maximum.
- Add aria-live and a data-testid to the prompt counter so the over-limit state
  is announced to assistive tech and reachable from browser tests.
@paulocastellano
paulocastellano merged commit 450b6fd into trypostit:main Jul 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants