Skip to content

Commit

Permalink
show validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Jan 24, 2016
1 parent d94d07b commit 2e87ccd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 18 additions & 3 deletions blog/src/components/posts_new.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import { reduxForm } from 'redux-form';
import { createPost } from '../actions/index';
import { Link } from 'react-router';

class PostsNew extends Component {
render() {
Expand All @@ -9,25 +10,33 @@ class PostsNew extends Component {
return (
<form onSubmit={handleSubmit(this.props.createPost)}>
<h3>Create A New Post</h3>
<div className="form-group">

<div className={`form-group ${title.touched && title.invalid ? 'has-danger' : ''}`}>
<label>Title</label>
<input type="text" className="form-control" {...title} />
<div className="text-help">
{title.touched ? title.error : ''}
</div>
</div>

<div className="form-group">
<div className={`form-group ${categories.touched && categories.invalid ? 'has-danger' : ''}`}>
<label>Categories</label>
<input type="text" className="form-control" {...categories} />
<div className="text-help">
{categories.touched ? categories.error : ''}
</div>
</div>

<div className="form-group">
<div className={`form-group ${content.touched && content.invalid ? 'has-danger' : ''}`}>
<label>Content</label>
<textarea className="form-control" {...content} />
<div className="text-help">
{content.touched ? content.error : ''}
</div>
</div>

<button type="submit" className="btn btn-primary">Submit</button>
<Link to="/" className="btn btn-danger">Cancel</Link>
</form>
);
}
Expand All @@ -39,6 +48,12 @@ function validate(values) {
if (!values.title) {
errors.title = 'Enter a username';
}
if (!values.categories) {
errors.categories = 'Enter categories';
}
if(!values.content) {
errors.content = 'Enter some content';
}

return errors;
}
Expand Down
3 changes: 3 additions & 0 deletions blog/style/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
form a {
margin-left: 5px;
}

0 comments on commit 2e87ccd

Please sign in to comment.