Skip to content

Commit fe13b1b

Browse files
committed
upgraded redux-form to v1.4.0
1 parent d19f26a commit fe13b1b

File tree

4 files changed

+68
-52
lines changed

4 files changed

+68
-52
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"react-redux": "^2.0.0",
7777
"react-router": "v1.0.0-beta2",
7878
"redux": "^2.0.0",
79-
"redux-form": "^1.3.4",
79+
"redux-form": "^1.4.0",
8080
"serialize-javascript": "^1.0.0",
8181
"serve-favicon": "^2.3.0",
8282
"serve-static": "^1.10.0",

src/components/SurveyForm.js

+25-51
Original file line numberDiff line numberDiff line change
@@ -47,66 +47,36 @@ class SurveyForm extends Component {
4747
asyncValidating,
4848
dirty,
4949
fields: {name, email, occupation},
50-
handleBlur,
51-
handleChange,
50+
active,
5251
handleSubmit,
5352
invalid,
5453
resetForm,
5554
pristine,
5655
valid
5756
} = this.props;
57+
const styles = require('./SurveyForm.scss');
58+
const renderInput = (field, label, showAsyncValidating) =>
59+
<div className={'form-group' + (field.error && field.touched ? ' has-error' : '')}>
60+
<label htmlFor={field.name} className="col-sm-2">{label}</label>
61+
<div className={'col-sm-8 ' + styles.inputGroup}>
62+
{showAsyncValidating && asyncValidating && <i className={'fa fa-cog fa-spin ' + styles.cog}/>}
63+
<input type="text" className="form-control" id={field.name} {...field}/>
64+
{field.error && field.touched && <div className="text-danger">{field.error}</div>}
65+
<div className={styles.flags}>
66+
{field.dirty && <span className={styles.dirty} title="Dirty">D</span>}
67+
{field.active && <span className={styles.active} title="Active">A</span>}
68+
{field.visited && <span className={styles.visited} title="Visited">V</span>}
69+
{field.touched && <span className={styles.touched} title="Touched">T</span>}
70+
</div>
71+
</div>
72+
</div>;
73+
5874
return (
5975
<div>
6076
<form className="form-horizontal" onSubmit={handleSubmit}>
61-
<div className={'form-group' + (name.error && name.touched ? ' has-error' : '')}>
62-
<label htmlFor="name" className="col-sm-2">
63-
Full Name
64-
{name.dirty && <span>*</span>}
65-
</label>
66-
67-
<div className="col-sm-10">
68-
<input type="text"
69-
className="form-control"
70-
id="name"
71-
value={name.value}
72-
onChange={handleChange('name')}
73-
onBlur={handleBlur('name')}/>
74-
{name.error && name.touched && <div className="text-danger">{name.error}</div>}
75-
</div>
76-
</div>
77-
<div className={'form-group' + (email.error && email.touched ? ' has-error' : '')}>
78-
<label htmlFor="email" className="col-sm-2">
79-
Email address
80-
{email.dirty && <span>*</span>}
81-
</label>
82-
83-
<div className="col-sm-10">
84-
<input type="email"
85-
className="form-control"
86-
id="email"
87-
value={email.value}
88-
onChange={handleChange('email')}
89-
onBlur={handleBlur('email')}/>
90-
{email.error && email.touched && <div className="text-danger">{email.error}</div>}
91-
{asyncValidating && <div>Validating...</div>}
92-
</div>
93-
</div>
94-
<div className={'form-group' + (occupation.error && occupation.touched ? ' has-error' : '')}>
95-
<label htmlFor="occupation" className="col-sm-2">
96-
Occupation
97-
{occupation.dirty && <span>*</span>}
98-
</label>
99-
100-
<div className="col-sm-10">
101-
<input type="text"
102-
className="form-control"
103-
id="occupation"
104-
value={occupation.value}
105-
onChange={handleChange('occupation')}
106-
onBlur={handleBlur('occupation')}/>
107-
{occupation.error && occupation.touched && <div className="text-danger">{occupation.error}</div>}
108-
</div>
109-
</div>
77+
{renderInput(name, 'Full Name')}
78+
{renderInput(email, 'Email', true)}
79+
{renderInput(occupation, 'Occupation')}
11080
<div className="form-group">
11181
<div className="col-sm-offset-2 col-sm-10">
11282
<button className="btn btn-success" onClick={handleSubmit}>
@@ -123,6 +93,10 @@ class SurveyForm extends Component {
12393

12494
<table className="table table-striped">
12595
<tbody>
96+
<tr>
97+
<th>Active Field</th>
98+
<td>{active}</td>
99+
</tr>
126100
<tr>
127101
<th>Dirty</th>
128102
<td className={dirty ? 'success' : 'danger'}>{dirty ? 'true' : 'false'}</td>

src/components/SurveyForm.scss

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.inputGroup {
2+
position: relative;
3+
}
4+
5+
.flags {
6+
position: absolute;
7+
right: 20px;
8+
top: 7px;
9+
& > * {
10+
margin: 0 2px;
11+
width: 20px;
12+
height: 20px;
13+
border-radius: 20px;
14+
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.4);
15+
color: white;
16+
float: right;
17+
text-align: center;
18+
}
19+
.active {
20+
background: linear-gradient(#cc0, #aa0);
21+
color: black;
22+
}
23+
.dirty {
24+
background: linear-gradient(#090, #060);
25+
}
26+
.visited {
27+
background: linear-gradient(#009, #006);
28+
}
29+
.touched {
30+
background: linear-gradient(#099, #066);
31+
}
32+
}
33+
34+
.cog {
35+
position: absolute;
36+
left: 0;
37+
top: 10px;
38+
}

src/views/Survey.js

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export default class Survey extends Component {
5151
<i className="fa fa-pencil"/> Initialize Form
5252
</button>
5353
</div>
54+
55+
<p>The circles to the left of the inputs correspond to flags provided by <code>redux-form</code>:
56+
Touched, Visited, Active, and Dirty.</p>
57+
5458
<SurveyForm onSubmit={::this.handleSubmit}/>
5559
</div>
5660
);

0 commit comments

Comments
 (0)