mirror of
https://github.com/fosrl/pangolin.git
synced 2025-06-20 20:35:43 +02:00
Fix #860
This commit is contained in:
parent
57315a36ee
commit
c409266954
1 changed files with 13 additions and 7 deletions
|
@ -82,7 +82,14 @@ export default function StepperForm() {
|
|||
);
|
||||
|
||||
const generateId = (name: string) => {
|
||||
return name.toLowerCase().replace(/\s+/g, "-");
|
||||
// Replace any character that is not a letter, number, space, or hyphen with a hyphen
|
||||
// Also collapse multiple hyphens and trim
|
||||
return name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\s-]/g, "-")
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/-+/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
};
|
||||
|
||||
async function orgSubmit(values: z.infer<typeof orgSchema>) {
|
||||
|
@ -207,23 +214,22 @@ export default function StepperForm() {
|
|||
type="text"
|
||||
{...field}
|
||||
onChange={(e) => {
|
||||
const orgId =
|
||||
generateId(
|
||||
e.target
|
||||
.value
|
||||
);
|
||||
// Prevent "/" in orgName input
|
||||
const sanitizedValue = e.target.value.replace(/\//g, "-");
|
||||
const orgId = generateId(sanitizedValue);
|
||||
orgForm.setValue(
|
||||
"orgId",
|
||||
orgId
|
||||
);
|
||||
orgForm.setValue(
|
||||
"orgName",
|
||||
e.target.value
|
||||
sanitizedValue
|
||||
);
|
||||
debouncedCheckOrgIdAvailability(
|
||||
orgId
|
||||
);
|
||||
}}
|
||||
value={field.value.replace(/\//g, "-")}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue