File tree Expand file tree Collapse file tree 6 files changed +201
-25
lines changed Expand file tree Collapse file tree 6 files changed +201
-25
lines changed Original file line number Diff line number Diff line change 22dist /
33node_modules /
44.snapshots /
5- * .min.js
5+ * .min.js
6+ * .d.ts
Original file line number Diff line number Diff line change 1111 "node": true
1212 },
1313 "parserOptions": {
14+ "parser": "@typescript-eslint/parser",
1415 "ecmaVersion": 2020,
1516 "ecmaFeatures": {
1617 "legacyDecorators": true,
3031 "react/no-unused-prop-types": 0,
3132 "import/export": 0
3233 }
33- }
34+ }
Original file line number Diff line number Diff line change 1+ import { ChangeEvent } from "react" ;
2+
13declare module "use-form-input-validator" {
2- import { ChangeEvent , SyntheticEvent } from "react" ;
3- interface InputField {
4- [ key : string ] : {
5- value : string
6- checks : string
7- validate : ( value : string ) => string
8- }
9- }
10- interface InputValues {
11- [ key : string ] : [ value : string ]
12- }
13- interface InputErrors {
14- [ key : string ] : [ error : string ]
4+ export type InputField = {
5+ value : string
6+ checks : string
7+ validate : ( value : string , values : Record < string , string > ) => string
158 }
169
17- export default function useFormValidator ( inputs : InputField ) : {
18- values : InputValues
19- errors : InputErrors
10+ export type FormValidator = {
11+ values : Record < string , InputField > ;
12+ errors : Record < string , string >
2013 updateField : ( event : ChangeEvent < HTMLInputElement > ) => void
2114 isFieldValid : ( key ) => boolean
2215 isAllFieldsValid : ( ) => boolean
23- } ;
16+ }
17+ export default function useFormValidator ( inputs : InputField ) : FormValidator ;
2418}
Original file line number Diff line number Diff line change 2828 "react" : " ^16.0.0"
2929 },
3030 "devDependencies" : {
31- "microbundle-crl " : " ^0.13.10 " ,
31+ "@typescript-eslint/parser " : " ^4.28.4 " ,
3232 "babel-eslint" : " ^10.0.3" ,
3333 "cross-env" : " ^7.0.2" ,
3434 "eslint" : " ^6.8.0" ,
4242 "eslint-plugin-react" : " ^7.17.0" ,
4343 "eslint-plugin-standard" : " ^4.0.1" ,
4444 "gh-pages" : " ^2.2.0" ,
45+ "microbundle-crl" : " ^0.13.10" ,
4546 "npm-run-all" : " ^4.1.5" ,
4647 "prettier" : " ^2.0.4" ,
4748 "react" : " ^16.13.1" ,
6566 "dependencies" : {
6667 "validator" : " ^13.1.17"
6768 }
68- }
69+ }
Original file line number Diff line number Diff line change @@ -142,7 +142,9 @@ const useFormValidator = (inputs) => {
142142 for ( const key in fields . values ) {
143143 const error = validate ( {
144144 value : fields . values [ key ] ,
145- checks : fields . checks [ key ]
145+ values : fields . values ,
146+ checks : fields . checks [ key ] ,
147+ customValidator : fields . validators [ key ]
146148 } )
147149
148150 if ( error ) valid = false
You can’t perform that action at this time.
0 commit comments