Skip to content

Commit

Permalink
v0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
stuyam committed Oct 24, 2017
1 parent d32d172 commit eda54f0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,26 @@ render: function() {
<div className="form-group">
<label>Title</label>
<input className="form-control" value={this.state.title} onChange={this.setTitle} />
{/* This is where the magic happens */}

{/********** This is where the magic happens ***********/}
{this.validator.message('title', this.state.title, 'required|alpha')}

</div>
<div className="form-group">
<label>Email</label>
<input className="form-control" value={this.state.email} onChange={this.setEmail} />
{/* This is where the magic happens */}

{/********** This is where the magic happens ***********/}
{this.validator.message('email', this.state.email, 'required|email', 'text-danger')}

</div>
<div className="form-group">
<label>Review</label>
<textarea className="form-control" value={this.state.review} onChange={this.setReview} />
{/* This is where the magic happens */}

{/********** This is where the magic happens ***********/}
{this.validator.message('review', this.state.review, 'required|min:20|max:120', false, {min: 'Custom min error'})}

</div>
<button className="btn btn-primary" onClick={this.submitForm}>Save Review</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "simple-react-validator",
"description": "A simple react form validator inspired by Laravel validation.",
"main": "dist/simple-react-validator.min.js",
"version": "0.0.4",
"version": "0.0.6",
"authors": [
"Stuart Yamartino"
],
Expand Down
11 changes: 9 additions & 2 deletions dist/simple-react-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var SimpleReactValidator = function () {

_classCallCheck(this, SimpleReactValidator);

this.fields = [];
this.fields = {};
this.errorMessages = {};
this.messagesShown = false;
this.rules = _extends({
accepted: { message: 'The :attribute must be accepted.', rule: function rule(val) {
Expand Down Expand Up @@ -107,6 +108,11 @@ var SimpleReactValidator = function () {
}

_createClass(SimpleReactValidator, [{
key: 'getErrorMessages',
value: function getErrorMessages() {
return this.errorMessages;
}
}, {
key: 'showMessages',
value: function showMessages() {
this.messagesShown = true;
Expand Down Expand Up @@ -152,6 +158,7 @@ var SimpleReactValidator = function () {
value: function message(field, value, testString, customClass) {
var customErrors = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};

this.errorMessages[field] = null;
this.fields[field] = true;
var tests = testString.split('|');
var rule, options, message;
Expand All @@ -166,6 +173,7 @@ var SimpleReactValidator = function () {
if (this.messagesShown) {
message = customErrors[rule] || customErrors.default || this.rules[rule].message.replace(':attribute', field.replace(/_/g, ' '));

this.errorMessages[field] = message;
if (options.length > 0 && this.rules[rule].hasOwnProperty('messageReplace')) {
return this._reactErrorElement(this.rules[rule].messageReplace(message, options));
} else {
Expand All @@ -175,7 +183,6 @@ var SimpleReactValidator = function () {
}
}
}

// Private Methods

}, {
Expand Down
2 changes: 1 addition & 1 deletion dist/simple-react-validator.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-react-validator",
"version": "0.0.5",
"version": "0.0.6",
"description": "A simple react form validator inspired by Laravel validation.",
"main": "dist/simple-react-validator.min.js",
"dependencies": {},
Expand Down

0 comments on commit eda54f0

Please sign in to comment.