File tree Expand file tree Collapse file tree 1 file changed +35
-4
lines changed Expand file tree Collapse file tree 1 file changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -2,23 +2,54 @@ import React, { Component } from 'react';
2
2
import { Field , reduxForm } from 'redux-form' ;
3
3
4
4
class PostsNew extends Component {
5
- renderTitleField ( field ) {
5
+ renderField ( field ) {
6
6
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 }
9
11
</ div >
10
12
) ;
11
13
}
12
14
13
15
render ( ) {
14
16
return (
15
17
< 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
+ />
17
29
</ form >
18
30
) ;
19
31
}
20
32
}
21
33
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
+
22
52
export default reduxForm ( {
53
+ validate,
23
54
form : 'PostsNewForm'
24
55
} ) ( PostsNew ) ;
You can’t perform that action at this time.
0 commit comments