From 43f389c29b7c408f2253f160a992da0cfb74b2ae Mon Sep 17 00:00:00 2001 From: Benny Samir Hierl Date: Sat, 19 Feb 2022 21:55:16 +0100 Subject: [PATCH] regex for url slug text added Signed-off-by: Benny Samir Hierl --- src/components/FormWishlist.vue | 6 +++--- src/components/InputText.vue | 15 ++++++++------- src/components/InputTextArea.vue | 15 ++++++++------- src/config/locales/de-DE.json | 3 ++- src/config/locales/en-US.json | 4 +++- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/components/FormWishlist.vue b/src/components/FormWishlist.vue index 855ec9d..c8f2482 100644 --- a/src/components/FormWishlist.vue +++ b/src/components/FormWishlist.vue @@ -84,9 +84,9 @@ const schema = object().shape( 300, t('components.form-wishlist.description.error-max') ), - slugUrlText: string().required( - t('components.form-wishlist.slug-text.error-requried') - ), + slugUrlText: string() + .required(t('components.form-wishlist.slug-text.error-requried')) + .matches(/^[\w-]+$/, t('components.form-wishlist.slug-text.error-regex')), imageSrc: string().when('imageFile', { is: (imageFile: string) => !imageFile || imageFile.length === 0, then: string().required( diff --git a/src/components/InputText.vue b/src/components/InputText.vue index 887e80a..8949975 100644 --- a/src/components/InputText.vue +++ b/src/components/InputText.vue @@ -51,11 +51,12 @@ const props = defineProps({ default: false, }, }) -const { value: inputValue, errorMessage, handleBlur, handleChange } = useField( - props.name, - undefined, - { - initialValue: props.value, - } -) +const { + value: inputValue, + errorMessage, + handleBlur, + handleChange, +} = useField(props.name, undefined, { + initialValue: props.value, +}) diff --git a/src/components/InputTextArea.vue b/src/components/InputTextArea.vue index d95e2a7..d6eb129 100644 --- a/src/components/InputTextArea.vue +++ b/src/components/InputTextArea.vue @@ -55,11 +55,12 @@ const props = defineProps({ default: false, }, }) -const { value: inputValue, errorMessage, handleBlur, handleChange } = useField( - props.name, - undefined, - { - initialValue: props.value, - } -) +const { + value: inputValue, + errorMessage, + handleBlur, + handleChange, +} = useField(props.name, undefined, { + initialValue: props.value, +}) diff --git a/src/config/locales/de-DE.json b/src/config/locales/de-DE.json index 7aab649..7401f25 100644 --- a/src/config/locales/de-DE.json +++ b/src/config/locales/de-DE.json @@ -136,7 +136,8 @@ }, "slug-text": { "label": "URL Slug-Text", - "error-requried": "URL Slug-Text wird benötigt." + "error-requried": "URL Slug-Text wird benötigt.", + "error-regex": "Unngültige URL Slug-Text." }, "image-src": { "label": "Bild-URL", diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index 36779a5..a283f0a 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -135,7 +135,9 @@ "error-max": "The max. length is 300 chars." }, "slug-text": { - "label": "URL Slug-Text" + "label": "URL Slug-Text", + "error-requried": "URL Slug-Text is required.", + "error-regex": "Invalid URL Slug-Text." }, "image-src": { "label": "Image-URL",