From fb2e3f1f9c99255ce6fe5430ee3ac710ec81c6d7 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 16 Jul 2024 11:25:06 +0200 Subject: [PATCH] feat: required validation --- src/composables/useValidator.js | 5 +++-- src/i18n/locale/en.yml | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/composables/useValidator.js b/src/composables/useValidator.js index a07f3e985..7a7032608 100644 --- a/src/composables/useValidator.js +++ b/src/composables/useValidator.js @@ -46,6 +46,9 @@ export function useValidator() { return !validator.isEmpty(value ? String(value) : '') || message; }, + required: (required, value) => { + return required ? !!value || t('globals.fieldRequired') : null; + }, length: (value) => { const options = { min: validation.min || validation.is, @@ -78,11 +81,9 @@ export function useValidator() { custom: (value) => validation.bindedFunction(value) || 'Invalid value', }; }; - // const requiredFieldRule = [(val) => validations({}).presence(val)]; return { validate, - // requiredFieldRule, validations, models, }; diff --git a/src/i18n/locale/en.yml b/src/i18n/locale/en.yml index 84a0f3edc..9bcb3f921 100644 --- a/src/i18n/locale/en.yml +++ b/src/i18n/locale/en.yml @@ -67,6 +67,7 @@ globals: allRows: 'All { numberRows } row(s)' markAll: Mark all requiredField: Required field + valueCantBeEmpty: Value cannot be empty class: clase type: Type reason: reason @@ -75,7 +76,7 @@ globals: notificationSent: Notification sent warehouse: Warehouse company: Company - fieldRequired: Field requdired + fieldRequired: Field required allowedFilesText: 'Allowed file types: { allowedContentTypes }' smsSent: SMS sent confirmDeletion: Confirm deletion