Skip to content

Commit

Permalink
Merge pull request #12 from anigenero/onblur-fix
Browse files Browse the repository at this point in the history
fix filter state
  • Loading branch information
anigenero authored Aug 19, 2021
2 parents 3ab4fd6 + 2ace4fa commit 3e9742a
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 24 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: build
defaults:
run:
shell: bash
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
on:
push:
branches:
- master
pull_request: {}
release:
types: [created]
jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 14.x
- run: npm ci
- run: npm run build
- run: npm run lint
- run: npm test
- uses: actions/upload-artifact@v2
with:
name: build-artifacts
path: |
coverage/
dist/
.npmignore
package.json
package-lock.json
LICENSE
README.md
coverage:
needs: build
runs-on: ubuntu-latest
steps:
- if: success()
uses: actions/download-artifact@v2
id: download
with:
name: build-artifacts
- uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage/lcov.info

publish:
needs: build
if: ${{ github.event_name == 'release' }}
runs-on: ubuntu-latest
steps:
- if: success()
uses: actions/download-artifact@v2
id: download
with:
name: build-artifacts
- uses: actions/setup-node@v2
with:
node-version: 14.x
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-class-validator",
"version": "1.2.0",
"version": "1.2.1",
"description": "React hook for validation with class-validator",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -28,7 +28,7 @@
},
"homepage": "https://github.com/anigenero/react-class-validator#readme",
"peerDependencies": {
"react": "^17.0.1"
"react": "^17.0.0"
},
"devDependencies": {
"@babel/core": "^7.12.13",
Expand All @@ -49,7 +49,8 @@
"jest": "^26.4.2",
"jest-cli": "^26.4.2",
"jest-environment-jsdom-global": "^2.0.4",
"react": "^17.0.1",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react-test-renderer": "^17.0.1",
"reflect-metadata": "^0.1.13",
"ts-jest": "^26.5.1",
Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,22 @@ export const useValidation = <T, K extends keyof T>(validationClass: Newable<T>)
);

if (filter.length > 0) {

const filteredErrors =
(Object.keys(validationErrors) as K[]).filter((key) =>
!filter.includes(key)
).reduce((accum, key) => ({
...accum,
[key]: validationErrors[key]
}), {});

console.dir(filteredErrors);

setErrors({
...validationErrors,
...filteredErrors,
...validation
});

} else {
setErrors(validation);
}
Expand Down

0 comments on commit 3e9742a

Please sign in to comment.