swarm ui: the create-agent name field says why a name is refused, beside the field
A name with an uppercase letter greyed out next with only the footer to say why. The text field now takes an error: it marks the field invalid, draws the reason under it and points aria-describedby at it. The create form passes it once something is typed, and nameProblem names the cause (uppercase first, then length, then other characters) instead of one catch-all rule. Next stays disabled, with the footer hint as before. The swarm UI doc says so.
This commit is contained in:
parent
da25f0a1c3
commit
94969b552e
1 changed files with 39 additions and 5 deletions
|
|
@ -28,9 +28,16 @@ export const STEP_TITLES: Record<Step, string> = {
|
|||
export const NAME_PATTERN = "[a-z0-9\\-]{1,63}";
|
||||
|
||||
export function nameProblem(name: string): string | null {
|
||||
return new RegExp(`^${NAME_PATTERN}$`).test(name)
|
||||
? null
|
||||
: "the name is 1-63 characters: lowercase letters, digits and hyphens";
|
||||
if (new RegExp(`^${NAME_PATTERN}$`).test(name)) return null;
|
||||
// Said for the likeliest slip first, so the field can name the cause.
|
||||
if (/[A-Z]/.test(name)) {
|
||||
return "uppercase letters aren't allowed, use lowercase";
|
||||
}
|
||||
if (name.length > 63) return "the name is at most 63 characters";
|
||||
if (/[^a-z0-9-]/.test(name)) {
|
||||
return "only lowercase letters, digits and hyphens are allowed";
|
||||
}
|
||||
return "the name is 1-63 characters: lowercase letters, digits and hyphens";
|
||||
}
|
||||
|
||||
/** The step after `step`, or `step` itself on the last. */
|
||||
|
|
|
|||
Loading…
Reference in a new issue