Skip to content

Commit

Permalink
feat: validate by string
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanvier committed Apr 26, 2024
1 parent f87d636 commit 559bde0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@wgr-sa/nuxt-form",
"description": "Form builder for Nuxt",
"version": "0.8.4",
"version": "0.8.5",
"repository": "https://github.com/WGR-SA/nuxt-form.git",
"author": "jeanvier",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/composables/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ export const useFormValidator = () => {

const validator = validators[rule.$params.type as keyof typeof validators]


const type_rules = [ 'isEmail', 'isNumber' ]
// validate type only if field is not empty
if (type_rules.includes(rule.$params.type) && (form.data.state[field].length === 0 || form.data.state[field] === null)) {
return
}

// @ts-ignore TODO: import only validation functions
const result = validator(form.data.state[field], rule.$params.options)
const result = validator(form.data.state[field].toString(), rule.$params.options)

if (!result && (form.data.state[field].length > 0 && form.data.state[field] !== 'false' || ['error', 'validate'].includes(form.state.status))) {
errors.value.push(rule.custom_message ?? rule.$message)
Expand Down

0 comments on commit 559bde0

Please sign in to comment.