diff --git a/src/components/Validation.js b/src/components/Validation.js index 260768a..d78c3e3 100644 --- a/src/components/Validation.js +++ b/src/components/Validation.js @@ -43,6 +43,10 @@ export default class Validation extends Component { return true } + clear() { + this.renderChild(this.props.children) + } + renderChild(child, error, helper, hint) { this.setState({ child: hint === undefined ? child : cloneElement(child, { diff --git a/src/core.js b/src/core.js index 6393f75..33beb4a 100644 --- a/src/core.js +++ b/src/core.js @@ -9,3 +9,9 @@ export const validate = (group, mute = false) => { return result } + +export const clear = group => { + for (const element of elements) + if (element.props.groups.includes(group)) + element.clear() +} diff --git a/src/index.js b/src/index.js index 22cfb6e..cd416f7 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,3 @@ +export { clear, validate } from './core' export { default as ValidationIn } from './components/ValidationIn' export { default as ValidationOut } from './components/ValidationOut' -export { validate } from './core' diff --git a/test/components/ValidationIn.test.js b/test/components/ValidationIn.test.js index b01c2c7..3e4ea95 100644 --- a/test/components/ValidationIn.test.js +++ b/test/components/ValidationIn.test.js @@ -5,9 +5,9 @@ import ValidationIn from '../../src/components/ValidationIn' const Select = () =>
select
-const ValidationInWrapper = props => ( - - ) diff --git a/test/components/ValidationOut.test.js b/test/components/ValidationOut.test.js index 207d179..b77b969 100644 --- a/test/components/ValidationOut.test.js +++ b/test/components/ValidationOut.test.js @@ -5,9 +5,9 @@ import ValidationOut from '../../src/components/ValidationOut' const Input = () =>
input
-const ValidationOutWrapper = props => ( - - +const ValidationOutWrapper = ({ disabled, ...other }) => ( + + ) diff --git a/test/core.test.js b/test/core.test.js index 3631ed1..e99d629 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -1,14 +1,14 @@ -import React from 'react' +import React, { Fragment } from 'react' import { mount } from 'enzyme' import ValidationIn from '../src/components/ValidationIn' import ValidationOut from '../src/components/ValidationOut' -import { elements, validate } from '../src/core' +import { clear, elements, validate } from '../src/core' const Textarea = () =>
textarea
const CoreWrapper = props => ( -
+ ( validators={props.validators3}>