{"record":{"id":"eaf80202fc862a6d","repo":"farion1231/cc-switch","slug":"display-name-is-required","errorCode":null,"errorMessage":"Display name is required","messagePattern":"Display name is required","errorType":"validation","errorClass":"PiFormValidationError","httpStatus":null,"severity":"warning","filePath":"src/components/providers/forms/PiProviderForm.tsx","lineNumber":1079,"sourceCode":"  }, []);\n\n  const submit = async (identity: ProviderFormData) => {\n    onSubmittingChange?.(true);\n    setFormError(null);\n    try {\n      if (!isEdit && selectedPresetId === null) {\n        throw new PiFormValidationError(t(\"pi.form.selectPresetRequired\"));\n      }\n      if (!parseJsonObject(identity.settingsConfig)) {\n        throw new PiFormValidationError(\n          t(\"jsonEditor.mustBeObject\"),\n          \"#pi-settings-config\",\n        );\n      }\n      const trimmedName = identity.name.trim();\n      const trimmedKey = providerKey.trim();\n      if (!trimmedName) {\n        throw new PiFormValidationError(\n          t(\"pi.form.nameRequired\"),\n          'input[name=\"name\"]',\n        );\n      }\n      if (!isEdit && !trimmedKey) {\n        throw new PiFormValidationError(\n          t(\"pi.form.providerKeyRequired\"),\n          \"#pi-provider-key\",\n        );\n      }\n      if (!isEdit && selectedPreset && apiKey.length === 0) {\n        throw new PiFormValidationError(\n          t(\"pi.form.credentialRequired\"),\n          \"#pi-api-key\",\n        );\n      }\n      if (!isEdit && models.length === 0) {\n        throw new PiFormValidationError(","sourceCodeStart":1061,"sourceCodeEnd":1097,"githubUrl":"https://github.com/farion1231/cc-switch/blob/0b5da510168914b251481654a568c3ffacd62cf4/src/components/providers/forms/PiProviderForm.tsx#L1061-L1097","documentation":"During submit(), PiProviderForm trims identity.name and throws this PiFormValidationError (pi.form.nameRequired) when the result is empty, focusing input[name=\"name\"]. Every Pi provider entry needs a human-readable display name because it is what the provider list and Pi's UI show. It fires in both create and edit modes.","triggerScenarios":"Submitting the form with the Name field empty or containing only whitespace; a programmatic submit whose formData has name: \"\" or name: \"   \".","commonSituations":"User tabs past the name field; an import/prefill path populates other fields but leaves name blank; whitespace-only name after copy-paste.","solutions":["Type a non-empty display name into the Name input (it is trimmed, so leading/trailing spaces do not count) and resubmit.","If prefilled data caused it, fix the source so name carries a real value before opening the form.","Add a required-attribute/inline validation on the name input so users get feedback before hitting submit."],"exampleFix":"// before\nconst identity = { name: \"   \", /* ... */ };\nawait submit(identity); // throws 'Display name is required'\n\n// after\nconst identity = { name: \"My Pi provider\", /* ... */ };\nawait submit(identity);","handlingStrategy":"validation","validationCode":"const nameOk = identity.name.trim().length > 0;\nif (!nameOk) focusInput('input[name=\"name\"]');","typeGuard":null,"tryCatchPattern":"catch (e) {\n  if (e instanceof PiFormValidationError) { setFormError(e.message); document.querySelector<HTMLInputElement>(e.fieldSelector ?? \"input\")?.focus(); return; }\n  throw e;\n}","preventionTips":["Mark the name input required and validate on blur.","Trim user input in controlled state so whitespace-only values are visible as empty."],"tags":["pi","form-validation","required-field","react"],"backgroundTag":"required-form-field-missing","analyzedSha":"0b5da510168914b251481654a568c3ffacd62cf4","analyzedAt":"2026-08-20T14:29:00.113Z","contentChangedAt":"2026-08-20T14:29:00.113Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}