Skip to content

Commit

Permalink
fix: fix validation triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffhandley committed Dec 19, 2017
1 parent fd905dd commit 84ab126
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 36 deletions.
36 changes: 8 additions & 28 deletions packages/demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions packages/demo/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import React, { Component } from 'react';
import classnames from 'classnames';
import logo from './logo.svg';
import './App.css';
import validate, {isValid} from 'strickland';
import required from 'strickland/lib/required';
import minLength from 'strickland/lib/minLength';
import compare from 'strickland/lib/compare';
import validate, {isValid, required, minLength, compare} from 'strickland';

function getValidationClassName(form, validation, fieldName) {
return classnames({
Expand Down Expand Up @@ -70,19 +67,19 @@ class App extends Component {
[fieldName]: value
};

if (this.state.validation) {
if (this.state.validation && this.state.validation.results) {
let validation = {
...this.state.validation,
results: {
...(this.state.validation ? this.state.validation.results : {})
}
};

if (this.state.validation[fieldName]) {
if (validation.results[fieldName]) {
validation.results[fieldName] = validate(this.rules[fieldName], value);
}

if (fieldName === 'password' && this.state.validation.confirmPassword) {
if (fieldName === 'password' && validation.results.confirmPassword) {
const validateProps = {compare: value};
validation.results.confirmPassword = validate(this.rules.confirmPassword, this.state.form.confirmPassword, validateProps);
}
Expand All @@ -98,7 +95,7 @@ class App extends Component {

const validation = validate(this.rules[fieldName], value);

if ((this.state.validation && this.state.validation[fieldName]) || isValid(validation)) {
if ((this.state.validation && this.state.validation.results && this.state.validation.results[fieldName]) || isValid(validation)) {
this.setState({
form: {
...this.state.form,
Expand Down

0 comments on commit 84ab126

Please sign in to comment.