1.0.9 • Published 6 years ago

self-validating-text-field v1.0.9

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

self-validating-text-field

Self Validating test field

import React, { Fragment } from "react";
import InputField from "self-validating-text-field";
import SimpleReactValidator from "simple-react-validator";

export default class extends React.Component {
  state = {
    email: "neerooz@gmail.com"
  };

  componentDidMount = () => {
    const validator = new SimpleReactValidator();
    this.setState({ validator });
  };

  submit = () => {
    if (this.validator.allValid()) {
      alert("You submitted the form and stuff!");
    } else {
      this.validator.showMessages();
      // rerender to show messages for the first time
      this.forceUpdate();
    }
  };

  render() {
    console.log("this.Validator", this.state.validator);
    return (
      <Fragment>
        {this.state.validator && (
          <InputField
            name="name"
            validator={this.state.validator}
            placeholder={"Name"}
            onChange={e => {
              const { value } = e.target;
              console.log("----------->", value);
            }}
            rules={"required|email"}
            value={this.state.email}
          />
        )}

        <button onClick={this.submit}>Submit</button>
      </Fragment>
    );
  }
}
1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago