FormWrap.js
1.2 KB
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
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';
import {reduxForm,destroy} from 'redux-form';
import cx from 'classnames';
import s from './form.scss';
class FormWrap extends React.Component {
constructor(props) {
super(props);
}
static propTypes = {
onSubmit:PropTypes.func
}
static defaultProps={
onSubmit:(values)=>{
console.log(values);
}
}
componentWillReceiveProps(nextProps){
const {defaultValues}=this.props;
}
render(){
const {fields}=this.props;
let children = this.props.children.map((section,i)=>{
if(!section)
return false;
else{
return React.cloneElement(section,{ fields:fields, key: i });
}
});
return(
<div >
{children}
</div>
)
}
}
const formWrapFactory=(option=>{
const {fields=[],defaultValues={},name='dynamic_form',destroyOnUnmount=true}=option;
return reduxForm({
form:name,
fields:fields,
destroyOnUnmount,
initialValues:defaultValues
})(FormWrap)
});
export default formWrapFactory;