vue3-form-validation
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -28,3 +28,3 @@ import { isReactive, watch } from 'vue'; | ||
$hasError: formField.hasError(), | ||
$validating: formField.validating(), | ||
$validating: formField.validating, | ||
async $onBlur() { | ||
@@ -85,3 +85,3 @@ if (!formField.touched) { | ||
} | ||
if (typeof value == 'object') { | ||
if (typeof value == 'object' && value !== null) { | ||
result[key] = {}; | ||
@@ -88,0 +88,0 @@ if (Array.isArray(value)) { |
@@ -149,3 +149,3 @@ import { computed, reactive, ref, unref } from 'vue'; | ||
if (typeof (ruleResult === null || ruleResult === void 0 ? void 0 : ruleResult.then) === 'function') { | ||
formField.rulesValidating.value++; | ||
formField.validating.value = true; | ||
const node = buffer.addLast(false); | ||
@@ -162,4 +162,4 @@ if (node.prev) { | ||
buffer.remove(node); | ||
formField.rulesValidating.value--; | ||
if (!node.value) { | ||
formField.validating.value = false; | ||
setError(formField, ruleNumber, error); | ||
@@ -166,0 +166,0 @@ } |
@@ -6,3 +6,3 @@ import { reactive, ref } from 'vue'; | ||
touched: boolean; | ||
rulesValidating: import("vue").Ref<number>; | ||
validating: import("vue").Ref<boolean>; | ||
private errors; | ||
@@ -14,4 +14,3 @@ private initialModelValue; | ||
hasError(): import("vue").ComputedRef<boolean>; | ||
validating(): import("vue").ComputedRef<boolean>; | ||
reset(toDefaultValues: boolean): void; | ||
} |
@@ -1,24 +0,41 @@ | ||
import { computed, isRef, reactive, ref, unref } from 'vue'; | ||
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); | ||
export class FormField { | ||
constructor(rules, modelValue) { | ||
this.touched = false; | ||
this.rulesValidating = ref(0); | ||
this.validating = ref(false); | ||
this.errors = reactive(rules.map(() => null)); | ||
modelValue = unref(modelValue); | ||
if (typeof modelValue === 'object' && modelValue !== null) { | ||
if (Array.isArray(modelValue)) { | ||
this.modelValue = ref(modelValue); | ||
this.initialModelValue = deepAssign([], 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 = deepAssign({}, this.modelValue); | ||
} | ||
else if (isArray(modelValue)) { | ||
this.modelValue = ref(modelValue); | ||
this.initialModelValue = deepAssign([], modelValue); | ||
} | ||
else { | ||
this.modelValue = ref(modelValue); | ||
this.initialModelValue = modelValue; | ||
} | ||
} | ||
else { | ||
this.modelValue = ref(modelValue); | ||
this.initialModelValue = modelValue; | ||
} | ||
} | ||
@@ -34,5 +51,2 @@ setError(ruleNumber, error) { | ||
} | ||
validating() { | ||
return computed(() => this.rulesValidating.value > 0); | ||
} | ||
reset(toDefaultValues) { | ||
@@ -39,0 +53,0 @@ this.touched = false; |
{ | ||
"name": "vue3-form-validation", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "Vue composition function for Form Validation", | ||
@@ -5,0 +5,0 @@ "author": { |
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
41039
849