-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.js
82 lines (77 loc) · 2.21 KB
/
Example.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React, {Component} from 'react'
import {connect} from 'react-redux'
import {formHOC} from '../../src'
class Example extends Component {
componentDidMount = () => {
this.props.setInitialValues({
foo: '123',
bar: 'abc',
baz: false
})
}
onSubmit = () => {
this.props.setInitialValues(this.props.currentValues.toJS())
}
render () {
const {currentValues, setValue} = this.props
const values = currentValues.toJS()
return (
<div className='row'>
<div className='col-xs-3 col-xs-offset-4'>
<form
style={{marginTop: 200}}
onSubmit={e => {
e.preventDefault()
this.onSubmit()
}}
>
<div className='form-group'>
<label>Foo</label>
<input
className='form-control'
value={values.foo || ''}
onChange={e => setValue('foo', e.target.value)}
/>
</div>
<div className='form-group'>
<label>Bar</label>
<input
className='form-control'
value={values.bar || ''}
onChange={e => setValue('bar', e.target.value)}
/>
</div>
<div className='checkbox'>
<label>
<input
type='checkbox'
checked={values.baz || false}
onChange={() => setValue('baz', !(values.baz || false))}
/> Baz
</label>
</div>
<div className='text-right'>
<button
type='button'
className='btn btn-default'
onClick={this.props.reset}
disabled={!this.props.isDirty}
>
Reset
</button>
<button
type='submit'
className='btn btn-primary'
disabled={!this.props.isDirty}
>
Save
</button>
</div>
</form>
</div>
</div>
)
}
}
const props = () => ({formName: 'test-form'})
export default connect(props)(formHOC(Example))