From 6bbb97048ea4cf06e0be547e8ac5e6a960de4f90 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 6 Feb 2025 16:18:32 +0100 Subject: [PATCH] try modularizing validated form input(s) --- .../Contributions/ContributionForm.vue | 102 +++++++++--------- .../src/components/Inputs/InputTextarea.vue | 16 ++- .../src/components/Inputs/LabeledInput.vue | 32 ++++++ .../src/components/Inputs/ValidatedInput.vue | 87 ++++++++------- frontend/src/locales/de.json | 11 +- frontend/src/locales/en.json | 5 + frontend/src/validationSchemas.js | 22 ++-- 7 files changed, 174 insertions(+), 101 deletions(-) create mode 100644 frontend/src/components/Inputs/LabeledInput.vue diff --git a/frontend/src/components/Contributions/ContributionForm.vue b/frontend/src/components/Contributions/ContributionForm.vue index 5c00cd54a..84eb7f31c 100644 --- a/frontend/src/components/Contributions/ContributionForm.vue +++ b/frontend/src/components/Contributions/ContributionForm.vue @@ -9,12 +9,11 @@ id="contribution-date" :model-value="formValues.date" name="date" - :state="dataFieldMeta.valid" :label="$t('contribution.selectDate')" :no-flip="true" class="mb-4 bg-248" type="date" - :schema-description="schemaDescription.fields.date" + :rules="validationSchema" @update:model-value="updateField" />
@@ -23,33 +22,33 @@
- - - diff --git a/frontend/src/components/Inputs/InputTextarea.vue b/frontend/src/components/Inputs/InputTextarea.vue index 2d1d2a12e..41e649265 100644 --- a/frontend/src/components/Inputs/InputTextarea.vue +++ b/frontend/src/components/Inputs/InputTextarea.vue @@ -16,7 +16,7 @@ @update:modelValue="currentValue = $event" /> - {{ errorMessage }} + {{ translatedErrorString }}
@@ -25,6 +25,8 @@ diff --git a/frontend/src/components/Inputs/LabeledInput.vue b/frontend/src/components/Inputs/LabeledInput.vue new file mode 100644 index 000000000..7fd4a9efe --- /dev/null +++ b/frontend/src/components/Inputs/LabeledInput.vue @@ -0,0 +1,32 @@ + + + diff --git a/frontend/src/components/Inputs/ValidatedInput.vue b/frontend/src/components/Inputs/ValidatedInput.vue index 9be51b9c1..50d869529 100644 --- a/frontend/src/components/Inputs/ValidatedInput.vue +++ b/frontend/src/components/Inputs/ValidatedInput.vue @@ -1,58 +1,73 @@ diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index dd34fbad4..0c71a5407 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -77,6 +77,7 @@ "myContributions": "Du hast noch keine Beiträge eingereicht." }, "noDateSelected": "Wähle irgendein Datum im Monat", + "noHours": "Bitte trage deine Stunden ein", "noOpenCreation": { "allMonth": "Für alle beiden Monate ist dein Schöpfungslimit erreicht. Den Nächsten Monat kannst du wieder 1000 GDD Schöpfen.", "lastMonth": "Für den ausgewählten Monat ist das Schöpfungslimit erreicht.", @@ -185,9 +186,17 @@ "username": "Benutzername", "username-placeholder": "Wähle deinen Benutzernamen", "validation": { - "gddCreationTime": "Das Feld {_field_} muss eine Zahl zwischen {min} und {max} mit höchstens einer Nachkommastelle sein", + "gddCreationTime": { + "min": "Die Stunden sollten mindestens {min} groß sein", + "max": "Die Stunden sollten höchsten {max} groß sein", + "decimal-places": "Die Stunden sollten maximal zwei Nachkommastellen enthalten" + }, "gddSendAmount": "Das Feld {_field_} muss eine Zahl zwischen {min} und {max} mit höchstens zwei Nachkommastellen sein", "is-not": "Du kannst dir selbst keine Gradidos überweisen", + "memo": { + "min": "Die Tätigkeitsbeschreibung sollte mindestens {min} Zeichen lang sein", + "max": "Die Tätigkeitsbeschreibung sollte höchstens {max} Zeichen lang sein" + }, "requiredField": "{fieldName} ist ein Pflichtfeld", "username-allowed-chars": "Der Nutzername darf nur aus Buchstaben (ohne Umlaute), Zahlen, Binde- oder Unterstrichen bestehen.", "username-hyphens": "Binde- oder Unterstriche müssen zwischen Buchstaben oder Zahlen stehen.", diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index 9346ea609..8804c7fe1 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -77,6 +77,7 @@ "myContributions": "You have not submitted any entries yet." }, "noDateSelected": "Choose any date in the month", + "noHours": "Please enter your hours", "noOpenCreation": { "allMonth": "For all two months your creation limit is reached. The next month you can create 1000 GDD again.", "lastMonth": "The creation limit is reached for the selected month.", @@ -188,6 +189,10 @@ "gddCreationTime": "The field {_field_} must be a number between {min} and {max} with at most one decimal place.", "gddSendAmount": "The {_field_} field must be a number between {min} and {max} with at most two digits after the decimal point", "is-not": "You cannot send Gradidos to yourself", + "memo": { + "min": "The job description should be at least {min} characters long", + "max": "The job description should not be longer than {max} characters" + }, "requiredField": "The {fieldName} field is required", "username-allowed-chars": "The username may only contain letters, numbers, hyphens or underscores.", "username-hyphens": "Hyphens or underscores must be in between letters or numbers.", diff --git a/frontend/src/validationSchemas.js b/frontend/src/validationSchemas.js index ae09a16a8..fe3ef901e 100644 --- a/frontend/src/validationSchemas.js +++ b/frontend/src/validationSchemas.js @@ -1,14 +1,10 @@ -import { object, string, date } from 'yup' +import { string } from 'yup' + +// TODO: only needed for grace period, before all inputs updated for using veeValidate + yup +export const isLanguageKey = (str) => str.match(/^(?!\.)[a-z][a-zA-Z0-9]*([.][a-z][a-zA-Z0-9]*)*(? ({ key: 'form.validation.memo.min', values: { min } })) + .max(255, ({max}) => ({ key: 'form.validation.memo.max', values: { max } })) -export const createContributionFormValidation = (t) => { - return object({ - // The date field is required and needs to be a valid date - // contribution date - date: date() - .required(t('contribution.noDateSelected')) - .min(new Date(new Date().setMonth(new Date().getMonth() - 1, 1)).toISOString().slice(0, 10)) // min date is first day of last month - .max(new Date().toISOString().slice(0, 10)) - .default(''), // date cannot be in the future - memo: string().required(t('')).min(5).max(255), - }) -}