FormWrap.js 1.2 KB
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;