add pattern matching for slug field not to use special characters
This commit is contained in:
parent
4a8b8e3c2f
commit
2519ed9496
1 changed files with 13 additions and 2 deletions
|
@ -32,6 +32,8 @@ interface Error {
|
||||||
code: ProductErrorCode | PageErrorCode;
|
code: ProductErrorCode | PageErrorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SLUG_REGEX = /^[a-z0-9]+(?:[\-a-z0-9]+)*$/;
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
const useStyles = makeStyles(
|
||||||
theme => ({
|
theme => ({
|
||||||
addressBar: {
|
addressBar: {
|
||||||
|
@ -116,8 +118,11 @@ const SeoForm: React.FC<SeoFormProps> = props => {
|
||||||
const classes = useStyles(props);
|
const classes = useStyles(props);
|
||||||
|
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
const [expanded, setExpansionStatus] = React.useState(false);
|
const [expanded, setExpansionStatus] = React.useState(false);
|
||||||
|
|
||||||
const toggleExpansion = () => setExpansionStatus(!expanded);
|
const toggleExpansion = () => setExpansionStatus(!expanded);
|
||||||
|
|
||||||
const shouldDisplayHelperText = helperText && !expanded;
|
const shouldDisplayHelperText = helperText && !expanded;
|
||||||
|
|
||||||
const getFilteredErrors = () =>
|
const getFilteredErrors = () =>
|
||||||
|
@ -155,7 +160,13 @@ const SeoForm: React.FC<SeoFormProps> = props => {
|
||||||
: getPageErrorMessage(error as PageErrorFragment, intl);
|
: getPageErrorMessage(error as PageErrorFragment, intl);
|
||||||
};
|
};
|
||||||
|
|
||||||
// .replace(/[^\x00-\x7F]/g, "")
|
const handleSlugChange = event => {
|
||||||
|
const { value } = event.target;
|
||||||
|
|
||||||
|
if (value === "" || !!value.match(SLUG_REGEX)) {
|
||||||
|
onChange(event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
|
@ -208,7 +219,7 @@ const SeoForm: React.FC<SeoFormProps> = props => {
|
||||||
value={slug?.slice(0, 69)}
|
value={slug?.slice(0, 69)}
|
||||||
disabled={loading || disabled}
|
disabled={loading || disabled}
|
||||||
placeholder={slug || slugify(slugPlaceholder, { lower: true })}
|
placeholder={slug || slugify(slugPlaceholder, { lower: true })}
|
||||||
onChange={onChange}
|
onChange={handleSlugChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
<FormSpacer />
|
<FormSpacer />
|
||||||
|
|
Loading…
Reference in a new issue