import React from 'react'; import {Field, Fieldset, createValue} from 'react-forms'; class IndividualFieldset extends Fieldset { static schema = { type: 'object', properties: { firstName: {type: 'string'}, lastName: {type: 'string'} } } static value = { firstName: 'John', lastName: 'Doe' } render() { let {label, ...props} = this.props; return (
); } } let schema = { type: 'object', properties: { mother: IndividualFieldset.schema, father: IndividualFieldset.schema } }; class FamilyForm extends React.Component { constructor(props) { super(props); this.state = {formValue: createValue({schema, value: props.value, onChange: this.onChange})}; } onChange = (nextFormValue) => { this.setState({formValue: nextFormValue}); this.props.onChange(nextFormValue.value); } render() { return ( ); } } // https://github.com/prometheusresearch/react-forms/issues/99 // https://github.com/prometheusresearch/react-forms/issues/100 // let value = { // mother: IndividualFieldset.value, // father: IndividualFieldset.value // } let value = {}; export default class Reusable extends React.Component { constructor(props) { super(props); this.onChange = this.onChange.bind(this); this.state = { value: value }; } onChange(value) { this.setState({value}); } render() { const {value} = this.state; return ({JSON.stringify(value)}