feat(ai-create): show character counter under the AI prompt field - #127
Merged
paulocastellano merged 5 commits intoJul 17, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The AI post prompt is validated with
max:2000on 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:length/2000, right-aligned under the field.text-destructive) once the prompt exceeds the limit.canSubmitnow alsochecks
promptText.length <= PROMPT_MAX— so the limit is enforced in the UIbefore the request is sent.
PROMPT_MAXmirrors the backendmax:2000rule so the two stay in sync.Frontend-only, single file:
resources/js/components/posts/create/AiPostWizard.vue.