-
Notifications
You must be signed in to change notification settings - Fork 68
/
SurveyFields.jsx
62 lines (52 loc) · 1.82 KB
/
SurveyFields.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @jsx React.DOM
*/
var React = require('react')
var getRadioOrCheckboxValue = require('../lib/radiobox-value')
var SurveyFields = React.createClass({
renderOptions: function(type, name, value, index) {
var isChecked = function() {
if (type == 'radio') return value == this.props.fieldValues[name]
if (type == 'checkbox') return this.props.fieldValues[name].indexOf(value) >= 0
return false
}.bind(this)
return (
<label key={index}>
<input type={type} name={name} value={value} defaultChecked={isChecked()} /> {value}
</label>
)
},
render: function() {
return (
<div>
<h2>Survey Question</h2>
<ul className="form-fields">
<li className="radio">
<span className="label">Age</span>
{['18-26', '27-38', '39-50', '51-62'].map(this.renderOptions.bind(this, 'radio', 'age'))}
</li>
<li className="checkbox">
<span className="label">Favorite Colors</span>
{['Blue', 'Red', 'Orange', 'Green'].map(this.renderOptions.bind(this, 'checkbox', 'colors'))}
</li>
<li className="form-footer">
<button className="btn -default pull-left" onClick={this.props.previousStep}>Back</button>
<button className="btn -primary pull-right" onClick={this.nextStep}>Save & Continue</button>
</li>
</ul>
</div>
)
},
nextStep: function() {
// Get values via querySelector
var age = document.querySelector('input[name="age"]:checked')
var colors = document.querySelectorAll('input[name="colors"]')
var data = {
age : getRadioOrCheckboxValue(age),
colors : getRadioOrCheckboxValue(colors)
}
this.props.saveValues(data)
this.props.nextStep()
}
})
module.exports = SurveyFields