@featherds/input-helper
Advanced tools
Comparing version 0.10.15 to 0.10.16
@@ -419,3 +419,3 @@ var __defProp = Object.defineProperty; | ||
const validation = Object.keys(controls).map((key) => { | ||
return controls[key](); | ||
return controls[key].validate(); | ||
}); | ||
@@ -425,6 +425,13 @@ errorMessages.value = validation.filter((x) => x.success === false); | ||
}; | ||
const _clearErrors = () => { | ||
Object.keys(controls).forEach((key) => { | ||
controls[key].clear(); | ||
}); | ||
errorMessages.value = []; | ||
return []; | ||
}; | ||
provide("featherFormErrors", errorMessages); | ||
provide("featherForm", { | ||
register: (input, validate) => { | ||
controls[input] = validate; | ||
register: (input, validator) => { | ||
controls[input] = validator; | ||
}, | ||
@@ -450,3 +457,3 @@ deregister: (input, revalidate = false) => { | ||
}); | ||
return { validate: _validate }; | ||
return { validate: _validate, clearErrors: _clearErrors }; | ||
}; | ||
@@ -483,2 +490,9 @@ const useValidation = (inputId, value, label, schema, errorFromInput) => { | ||
}; | ||
const clear = () => { | ||
errorMessage.value = ""; | ||
}; | ||
const validator = { | ||
clear, | ||
validate | ||
}; | ||
if (errorFromInput && isRef(errorFromInput)) { | ||
@@ -491,3 +505,3 @@ watch(errorFromInput, () => { | ||
if (curr && form) { | ||
form.register(curr, validate); | ||
form.register(curr, validator); | ||
} | ||
@@ -494,0 +508,0 @@ if (old && form) { |
{ | ||
"name": "@featherds/input-helper", | ||
"version": "0.10.15", | ||
"version": "0.10.16", | ||
"publishConfig": { | ||
@@ -12,3 +12,3 @@ "access": "public" | ||
"dependencies": { | ||
"@featherds/styles": "^0.10.15", | ||
"@featherds/styles": "^0.10.16", | ||
"vue": "^3.1.0-0" | ||
@@ -21,3 +21,3 @@ }, | ||
"types": "./src/index.d.ts", | ||
"gitHead": "dda92cf914287cfa8899add188f45e5e778eca9b" | ||
"gitHead": "b6f44a1ec626c4c2f10ac3cc9ee2bb0b815bdd1c" | ||
} |
@@ -12,4 +12,8 @@ import { provide, ref } from "vue"; | ||
} | ||
export interface IValidator { | ||
validate: () => IValidationResult; | ||
clear: () => void; | ||
} | ||
export interface IFeatherForm { | ||
register: (input: string, validate: () => IValidationResult) => void; | ||
register: (input: string, validator: IValidator) => void; | ||
deregister: (input: string, revalidate?: boolean) => void; | ||
@@ -25,7 +29,7 @@ reregister: (ol: string, nw: string) => void; | ||
const useForm = () => { | ||
let controls = {} as Record<string, () => IValidationResult>; | ||
let controls = {} as Record<string, IValidator>; | ||
const errorMessages = ref([] as IValidationFailure[]); | ||
const _validate = () => { | ||
const validation = Object.keys(controls).map((key) => { | ||
return controls[key](); | ||
return controls[key].validate(); | ||
}); | ||
@@ -37,2 +41,9 @@ errorMessages.value = validation.filter( | ||
}; | ||
const _clearErrors = () => { | ||
Object.keys(controls).forEach((key) => { | ||
controls[key].clear(); | ||
}); | ||
errorMessages.value = [] as IValidationFailure[]; | ||
return []; | ||
}; | ||
@@ -42,4 +53,4 @@ provide("featherFormErrors", errorMessages); | ||
provide("featherForm", { | ||
register: (input: string, validate: () => IValidationResult) => { | ||
controls[input] = validate; | ||
register: (input: string, validator: IValidator) => { | ||
controls[input] = validator; | ||
}, | ||
@@ -59,3 +70,3 @@ deregister: (input: string, revalidate = false) => { | ||
return acc; | ||
}, {} as Record<string, () => IValidationResult>); | ||
}, {} as Record<string, IValidator>); | ||
@@ -67,5 +78,5 @@ controls = newControls; | ||
return { validate: _validate }; | ||
return { validate: _validate, clearErrors: _clearErrors }; | ||
}; | ||
export { useForm }; |
@@ -6,2 +6,3 @@ import { inject, ref, provide, watch, isRef, onBeforeUnmount, Ref } from "vue"; | ||
IValidationSuccess, | ||
IValidator, | ||
} from "./useForm"; | ||
@@ -46,2 +47,9 @@ const useValidation = ( | ||
}; | ||
const clear = () => { | ||
errorMessage.value = ""; | ||
}; | ||
const validator = { | ||
clear, | ||
validate, | ||
} as IValidator; | ||
//watch for error from input | ||
@@ -58,3 +66,3 @@ //server side error, run validation when it occurs | ||
if (curr && form) { | ||
form.register(curr, validate); | ||
form.register(curr, validator); | ||
} | ||
@@ -61,0 +69,0 @@ if (old && form) { |
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
85837
1288
Updated@featherds/styles@^0.10.16