From cebd6adbd2aa97852106f03f4d184ce67a01640b Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Fri, 30 Aug 2024 17:48:32 +0300 Subject: [PATCH] fixed validation --- src/components/forms/ScaleQuestion.vue | 61 ++++++--- src/components/forms/SelectorQuestion.vue | 59 +++++--- src/components/forms/TextQuestion.vue | 49 +++++-- src/styles/form/view.scss | 128 ++++++++++++++++++ src/views/form/View.vue | 158 +++------------------- 5 files changed, 261 insertions(+), 194 deletions(-) create mode 100644 src/styles/form/view.scss diff --git a/src/components/forms/ScaleQuestion.vue b/src/components/forms/ScaleQuestion.vue index 9625c54..60ba22b 100644 --- a/src/components/forms/ScaleQuestion.vue +++ b/src/components/forms/ScaleQuestion.vue @@ -1,25 +1,32 @@ @@ -27,7 +34,21 @@ import { ref, computed } from 'vue' import { PhCardsThree, PhCaretCircleUpDown } from '@phosphor-icons/vue' +import '@/styles/form/view.scss'; + const props = defineProps({ + label: { + type: String, + default: '' + }, + description: { + type: String, + default: null + }, + imageUrl: { + type: String, + default: null + }, min: { type: Number, required: true diff --git a/src/components/forms/SelectorQuestion.vue b/src/components/forms/SelectorQuestion.vue index d7d5292..b79b8b5 100644 --- a/src/components/forms/SelectorQuestion.vue +++ b/src/components/forms/SelectorQuestion.vue @@ -1,27 +1,34 @@ @@ -30,7 +37,21 @@ import { ref, watch } from 'vue' import { PhCaretCircleUpDown, PhXCircle } from '@phosphor-icons/vue' import { normalizeCountForm } from '@/utils/formation' +import '@/styles/form/view.scss'; + const props = defineProps({ + label: { + type: String, + default: '' + }, + description: { + type: String, + default: null + }, + imageUrl: { + type: String, + default: null + }, minValues: { type: Number, default: 1 diff --git a/src/components/forms/TextQuestion.vue b/src/components/forms/TextQuestion.vue index 3dd486a..872121d 100644 --- a/src/components/forms/TextQuestion.vue +++ b/src/components/forms/TextQuestion.vue @@ -1,18 +1,25 @@ @@ -22,7 +29,21 @@ import { PhXCircle } from '@phosphor-icons/vue' import { validateSNILS, validateTIN } from '@/utils/validators' import { normalizeCountForm } from '@/utils/formation' +import '@/styles/form/view.scss'; + const props = defineProps({ + label: { + type: String, + default: '' + }, + description: { + type: String, + default: null + }, + imageUrl: { + type: String, + default: null + }, minLength: { type: Number, default: null diff --git a/src/styles/form/view.scss b/src/styles/form/view.scss new file mode 100644 index 0000000..e974506 --- /dev/null +++ b/src/styles/form/view.scss @@ -0,0 +1,128 @@ +.default-card { + width: 100%; + border: 1px solid var(--color-main-border); + background: var(--color-secondary-background); + padding: 25px; + border-radius: 1rem; +} +.form-red { + border: 1px solid var(--color-red); +} + +.view { + margin: 40px 0; + &-form { + display: flex; + flex-direction: column; + //gap: 25px 0; + + &-container { + margin: 0 auto; + max-width: 800px; + } + + &-title { + border: 1px solid var(--color-third-border); + //margin-bottom: 20px; + + & h2 { + margin-top: 10px; + margin-bottom: 4px; + } + } + + &-info { + display: flex; + align-items: center; + gap: 0 11px; + color: var(--color-subtext); + font-size: 16px; + + &--sign { + min-width: 23px; + min-height: 23px; + } + } + + &-q { + display: flex; + flex-direction: column; + gap: 20px 0; + margin: 35px auto; + + &:empty { + margin: 10px 0; + } + + &-title { + margin-bottom: 25px; + + & h3 { + font-weight: 400; + margin-bottom: 8px; + } + + & p { + color: var(--color-description); + font-size: 17px; + } + } + } + + &-send, + &-next { + border-radius: 1rem; + padding: 10px 30px; + } + + &-send { + padding: 15px 30px; + border-radius: 1rem; + background: var(--color-main); + color: var(--color-alternative-text); + + &:hover { + opacity: 0.9; + } + + @media (max-width: 500px) { + width: 100%; + } + + &-space { + display: flex; + //justify-content: space-between; + align-items: center; + gap: 10px 30px; + + @media (max-width: 500px) { + flex-direction: column; + } + } + } + } + + @media (max-width: 500px) { + .form-title { + font-size: 1.3em; + } + + .form-description { + font-size: 0.9em; + } + + .form-q-title { + font-size: 1.1em; + } + + .form-q-description { + font-size: 0.88em; + } + } + + @media (max-width: 380px) { + .form-title { + font-size: 1.17em; + } + } +} \ No newline at end of file diff --git a/src/views/form/View.vue b/src/views/form/View.vue index 6cfe9e2..60eb198 100644 --- a/src/views/form/View.vue +++ b/src/views/form/View.vue @@ -10,6 +10,8 @@ import { useRoute } from 'vue-router' import { PhInfo, PhCardsThree } from '@phosphor-icons/vue' import { validateSNILS, validateTIN } from '@/utils/validators' +import '@/styles/form/view.scss'; + const route = useRoute() const data = ref({}) @@ -31,19 +33,18 @@ async function prepareNewPage() { } function beforeSubmitValidate() { - for (let question_id of currentPage.value.questions.keys()) { - const question = currentPage.value.questions[question_id] + for (let question of currentPage.value.questions) { const answer = answers.value[question.id] if (!answer) return false; - if (question.required && !(answer.value || answer.values)) return false; + if (question.required && !answer.value && !answer.values) return false; if (question.question_type === 1 && answer.value) { if (!question.validator && question.min_length && answer.value.length < question.min_length) return false; if (question.validator === 1 && !validateTIN(answer.value)) return false; if (question.validator === 2 && !validateSNILS(answer.value)) return false; - } else if (question.question_type === 2) { - return question.required && answer.values.length >= question.min_values + } else if (question.question_type === 2 && !(question.required && answer.values.length >= question.min_values)) { + return false } } return true @@ -105,14 +106,12 @@ onMounted(async () => {
-
-
-

{{ question.label }}

-

{{ question.description }}

-
- image by user +
{ /> { /> {
- +