Skip to content

Commit 81607fc

Browse files
WIP - fix for higer order components
1 parent 65d0da3 commit 81607fc

File tree

5 files changed

+118
-3
lines changed

5 files changed

+118
-3
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@
5353
"gulp-mocha": "^3.0.1",
5454
"gulp-plumber": "^1.1.0",
5555
"isparta": "^4.0.0",
56+
"joi": "^10.2.2",
57+
"joi-validation-strategy": "^0.3.3",
58+
"json-loader": "^0.5.4",
5659
"promise": "^7.1.1",
5760
"react": "^15.3.2",
5861
"react-addons-test-utils": "^15.3.2",
5962
"react-dom": "^15.3.2",
63+
"react-validation-mixin": "^5.4.0",
6064
"sinon": "^1.17.7",
6165
"sinon-chai": "^2.8.0",
6266
"style-loader": "^0.13.1",

src/examples/Example.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Step2 from './Step2'
77
import Step3 from './Step3'
88
import Step4 from './Step4'
99
import Step5 from './Step5'
10+
import StepValidationTest from './StepValidationTest'
1011

1112
export default class Example extends Component {
1213
constructor(props) {
@@ -38,6 +39,7 @@ export default class Example extends Component {
3839
render() {
3940
const steps =
4041
[
42+
{name: 'StepValidationTest', component: <StepValidationTest getStore={() => (this.getStore())} updateStore={(u) => {this.updateStore(u)}} />},
4143
{name: 'Step1', component: <Step1 getStore={() => (this.getStore())} updateStore={(u) => {this.updateStore(u)}} />},
4244
{name: 'Step2', component: <Step2 getStore={() => (this.getStore())} updateStore={(u) => {this.updateStore(u)}} />},
4345
{name: 'Step3', component: <Step3 getStore={() => (this.getStore())} updateStore={(u) => {this.updateStore(u)}} />},

src/examples/StepValidationTest.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
'use strict';
2+
3+
import React, { Component, PropTypes } from 'react';
4+
import validation from 'react-validation-mixin';
5+
import strategy from 'joi-validation-strategy';
6+
import Joi from 'joi';
7+
8+
class StepValidationTest extends Component {
9+
constructor(props) {
10+
super(props);
11+
this.state = {
12+
email: ''
13+
};
14+
15+
this.validatorTypes = {
16+
email: Joi.string().email(),
17+
};
18+
19+
this.getValidatorData = this.getValidatorData.bind(this);
20+
this.isValidated = this.isValidated.bind(this);
21+
this.renderHelpText = this.renderHelpText.bind(this);
22+
}
23+
24+
getValidatorData() {
25+
return {
26+
email: this.refs.email.value,
27+
}
28+
};
29+
30+
isValidated() {
31+
const isDataValid = this.props.isValid();
32+
33+
return isDataValid;
34+
}
35+
36+
onChange(e) {
37+
const state = {};
38+
39+
state[e.target.id] = e.target.value ;
40+
this.setState(state);
41+
}
42+
43+
renderHelpText(message, id) {
44+
return (<div key={id}><span>{message}</span></div>);
45+
};
46+
47+
render() {
48+
// explicit class assigning based on validation
49+
let notValidClasses = {};
50+
notValidClasses.emailCls = this.props.isValid('email') ?
51+
'no-error col-md-8' : 'has-error col-md-8';
52+
53+
return (
54+
<div className="step step2-2">
55+
<div className="row">
56+
<form id="Form" className="form-horizontal">
57+
<div className="form-group">
58+
<label className="col-md-12 control-label">
59+
<h1>Step 2: Enter your Details</h1>
60+
</label>
61+
</div>
62+
<div className="form-group col-md-12">
63+
<label className="control-label col-md-4">
64+
Email
65+
</label>
66+
<div className={notValidClasses.emailCls}>
67+
<input
68+
ref="email"
69+
autoComplete="off"
70+
type="email"
71+
placeholder="[email protected]"
72+
className="form-control"
73+
defaultValue={this.state.email}
74+
required
75+
onBlur={this.props.handleValidation('email')}
76+
onChange={this.onChange.bind(this)}
77+
/>
78+
</div>
79+
{this.props.getValidationMessages('email').map(this.renderHelpText)}
80+
</div>
81+
</form>
82+
</div>
83+
</div>
84+
)
85+
}
86+
}
87+
88+
StepValidationTest.propTypes = {
89+
errors: PropTypes.object,
90+
validate: PropTypes.func,
91+
isValid: PropTypes.func,
92+
handleValidation: PropTypes.func,
93+
getValidationMessages: PropTypes.func,
94+
clearValidations: PropTypes.func,
95+
getStore: PropTypes.func,
96+
updateStore: PropTypes.func,
97+
};
98+
99+
export default validation(strategy)(StepValidationTest);

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export default class StepZilla extends Component {
218218

219219
// are we allowed to move forward? via the next button or via jumpToStep?
220220
stepMoveAllowed(skipValidationExecution = false) {
221+
debugger;
221222
let proceed = false;
222223

223224
if (this.props.dontValidate) {

webpack.config.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@ module.exports = {
1717
loader: 'babel-loader'
1818
},
1919
{
20-
test: /\.css$/,
21-
loader: 'style-loader!css-loader'
22-
}
20+
test: /\.css$/,
21+
loader: 'style-loader!css-loader'
22+
},
23+
{
24+
test: /\.json$/,
25+
loader: 'json-loader'
26+
}
2327
]
2428
},
2529
resolve: {
2630
extensions: ['', '.js', '.json']
31+
},
32+
node: {
33+
net: 'empty',
34+
tls: 'empty',
35+
dns: 'empty'
2736
}
2837
};

0 commit comments

Comments
 (0)