Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Content Model validation message for name field #1303

Merged
merged 2 commits into from
Oct 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useCallback } from "react";
import { css } from "emotion";
import { useRouter } from "@webiny/react-router";
import { Form } from "@webiny/form";
Expand Down Expand Up @@ -58,6 +58,16 @@ const NewContentModelDialog: React.FC<NewContentModelDialogProps> = ({
return { value: item.id, label: item.name };
});

const nameValidator = useCallback(name => {
if (!name.charAt(0).match(/[a-zA-Z]/)) {
throw new Error("Value is not valid - must not start with a number.");
}
if (name.trim().toLowerCase() === "id") {
throw new Error('Value is not valid - "id" is an auto-generated field.');
}
return true;
}, undefined);

return (
<Dialog
open={open}
Expand Down Expand Up @@ -102,7 +112,10 @@ const NewContentModelDialog: React.FC<NewContentModelDialogProps> = ({
<Cell span={12}>
<Bind
name={"name"}
validators={validation.create("required,maxLength:100")}
validators={[
validation.create("required,maxLength:100"),
nameValidator
]}
>
<Input
label={t`Name`}
Expand Down