Skip to content

Commit fdcf675

Browse files
author
Artis Coleman
committed
Finished 138
1 parent caf4e1d commit fdcf675

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

src/components/posts_new.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,54 @@ import React, { Component } from 'react';
22
import { Field, reduxForm } from 'redux-form';
33

44
class PostsNew extends Component {
5-
renderTitleField(field) {
5+
renderField(field) {
66
return (
7-
<div>
8-
<input type="text" {...field.input} />
7+
<div className="form-group">
8+
<label>{field.label}</label>
9+
<input className="form-control" type="text" {...field.input} />
10+
{field.meta.error}
911
</div>
1012
);
1113
}
1214

1315
render() {
1416
return (
1517
<form>
16-
<Field name="title" component={this.renderTitleField} />
18+
<Field label="Title" name="title" component={this.renderField} />
19+
<Field
20+
label="Categories"
21+
name="categories"
22+
component={this.renderField}
23+
/>
24+
<Field
25+
label="Post Content"
26+
name="content"
27+
component={this.renderField}
28+
/>
1729
</form>
1830
);
1931
}
2032
}
2133

34+
function validate(values) {
35+
const errors = {};
36+
37+
if (!values.title) {
38+
error.title = 'Enter a title!';
39+
}
40+
41+
if (!values.categories) {
42+
error.categories = 'Enter some categories!';
43+
}
44+
45+
if (!values.content) {
46+
error.content = 'Enter some content!';
47+
}
48+
49+
return errors;
50+
}
51+
2252
export default reduxForm({
53+
validate,
2354
form: 'PostsNewForm'
2455
})(PostsNew);

0 commit comments

Comments
 (0)