vue3-form-validation
Advanced tools
Comparing version 3.1.2 to 3.1.3
@@ -0,1 +1,5 @@ | ||
export { cleanupForm } from './form-helper/cleanup-form/cleanupForm'; | ||
export { getResultFormData } from './form-helper/get-result-form-data/getResultFormData'; | ||
export { resetFields } from './form-helper/reset-fields/resetFields'; | ||
export { transformFormData } from './form-helper/transform-form-data/transformFormData'; | ||
export { deepIterator } from './deep-iterator/deepIterator'; | ||
@@ -8,1 +12,2 @@ export { LinkedList } from './linked-list/LinkedList'; | ||
export { set } from './set/set'; | ||
export { isNotNull, isArray, isObject, isField, isTransformedField } from './type-guards/typeGuards'; |
@@ -0,1 +1,5 @@ | ||
export { cleanupForm } from './form-helper/cleanup-form/cleanupForm'; | ||
export { getResultFormData } from './form-helper/get-result-form-data/getResultFormData'; | ||
export { resetFields } from './form-helper/reset-fields/resetFields'; | ||
export { transformFormData } from './form-helper/transform-form-data/transformFormData'; | ||
export { deepIterator } from './deep-iterator/deepIterator'; | ||
@@ -8,1 +12,2 @@ export { LinkedList } from './linked-list/LinkedList'; | ||
export { set } from './set/set'; | ||
export { isNotNull, isArray, isObject, isField, isTransformedField } from './type-guards/typeGuards'; |
import { reactive } from 'vue'; | ||
import { path, PromiseCancel } from '../common'; | ||
import { cleanupForm, getResultFormData, path, PromiseCancel, resetFields, transformFormData } from '../common'; | ||
import { Form } from '../form/Form'; | ||
import { ValidationError } from '../form/ValidationError'; | ||
import { cleanupForm, getResultFormData, resetFields, transformFormData } from './helper'; | ||
/** | ||
@@ -7,0 +6,0 @@ * |
@@ -12,3 +12,3 @@ import { Rule } from '../composition/useValidation'; | ||
submitting: import("vue").Ref<boolean>; | ||
registerField(uid: number, rules: Rule[], modelValue?: unknown): FormField; | ||
registerField(uid: number, rules: Rule[], modelValue: unknown): FormField; | ||
getErrors(): import("vue").ComputedRef<string[]>; | ||
@@ -15,0 +15,0 @@ resetFields(toDefaultValues?: boolean): void; |
import { reactive, ref } from 'vue'; | ||
import { Rule } from '../composition/useValidation'; | ||
export declare class FormField { | ||
private errors; | ||
private initialModelValue; | ||
modelValue: ReturnType<typeof ref> | ReturnType<typeof reactive>; | ||
touched: boolean; | ||
validating: import("vue").Ref<boolean>; | ||
private errors; | ||
private initialModelValue; | ||
constructor(rules: Rule[], modelValue: unknown); | ||
constructor(rules: Rule[], modelValue: any); | ||
setError(ruleNumber: number, error: string | null): void; | ||
@@ -11,0 +11,0 @@ getErrors(): import("vue").ComputedRef<string[]>; |
@@ -1,6 +0,3 @@ | ||
import { computed, isReactive, isRef, reactive, ref } from 'vue'; | ||
import { deepAssign } from '../common/deep-assign/deepAssign'; | ||
const notNull = (value) => value !== null; | ||
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value); | ||
const isArray = (value) => Array.isArray(value); | ||
import { computed, isReactive, isRef, reactive, ref, unref } from 'vue'; | ||
import { isArray, isObject, isNotNull } from '../common'; | ||
export class FormField { | ||
@@ -11,31 +8,15 @@ constructor(rules, modelValue) { | ||
this.errors = reactive(rules.map(() => null)); | ||
this.initialModelValue = JSON.parse(JSON.stringify(unref(modelValue))); | ||
if (isRef(modelValue)) { | ||
this.modelValue = modelValue; | ||
if (isObject(modelValue.value)) { | ||
this.initialModelValue = deepAssign({}, modelValue.value); | ||
} | ||
else if (isArray(modelValue.value)) { | ||
this.initialModelValue = deepAssign([], modelValue.value); | ||
} | ||
else { | ||
this.initialModelValue = modelValue.value; | ||
} | ||
} | ||
else if (isReactive(modelValue)) { | ||
this.modelValue = modelValue; | ||
this.initialModelValue = deepAssign({}, modelValue); | ||
} | ||
else if (isObject(modelValue)) { | ||
this.modelValue = reactive(modelValue); | ||
this.initialModelValue = JSON.parse(JSON.stringify(unref(this.modelValue))); | ||
} | ||
else { | ||
if (isObject(modelValue)) { | ||
this.modelValue = reactive(modelValue); | ||
this.initialModelValue = deepAssign({}, this.modelValue); | ||
} | ||
else if (isArray(modelValue)) { | ||
this.modelValue = ref(modelValue); | ||
this.initialModelValue = deepAssign([], modelValue); | ||
} | ||
else { | ||
this.modelValue = ref(modelValue); | ||
this.initialModelValue = modelValue; | ||
} | ||
this.modelValue = ref(modelValue); | ||
} | ||
@@ -47,3 +28,3 @@ } | ||
getErrors() { | ||
return computed(() => this.errors.filter(notNull)); | ||
return computed(() => this.errors.filter(isNotNull)); | ||
} | ||
@@ -57,10 +38,16 @@ hasError() { | ||
if (isRef(this.modelValue)) { | ||
this.modelValue.value = this.initialModelValue; | ||
if (isArray(this.modelValue.value)) { | ||
this.modelValue.value = JSON.parse(JSON.stringify(this.initialModelValue)); | ||
} | ||
else { | ||
this.modelValue.value = this.initialModelValue; | ||
} | ||
} | ||
else { | ||
deepAssign(this.modelValue, this.initialModelValue); | ||
const copy = JSON.parse(JSON.stringify(this.initialModelValue)); | ||
Object.assign(this.modelValue, copy); | ||
} | ||
} | ||
deepAssign(this.errors, this.errors.map(() => null)); | ||
Object.assign(this.errors, this.errors.map(() => null)); | ||
} | ||
} |
{ | ||
"name": "vue3-form-validation", | ||
"version": "3.1.2", | ||
"version": "3.1.3", | ||
"description": "Vue composition function for Form Validation", | ||
@@ -42,4 +42,4 @@ "author": { | ||
"@types/node": "^15.3.0", | ||
"@typescript-eslint/eslint-plugin": "^4.23.0", | ||
"@typescript-eslint/parser": "^4.23.0", | ||
"@typescript-eslint/eslint-plugin": "^4.24.0", | ||
"@typescript-eslint/parser": "^4.24.0", | ||
"@vitejs/plugin-vue": "^1.2.2", | ||
@@ -63,3 +63,3 @@ "@vue/compiler-sfc": "^3.0.11", | ||
"typescript": "^4.2.4", | ||
"vite": "^2.3.2", | ||
"vite": "^2.3.3", | ||
"vue": "^3.0.7", | ||
@@ -66,0 +66,0 @@ "vue-router": "^4.0.4" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41482
45
832