@darwino/darwino-react
Version:
A set of Javascript classes and utilities
54 lines (43 loc) • 1.29 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
/*
* (c) Copyright Darwino Inc. 2014-2017.
*/
import React, { Component } from "react";
import PropTypes from 'prop-types';
import { FormSection } from 'redux-form';
import BaseDocumentForm from './BaseDocumentForm';
/*
*
*/
class BaseDocumentSubform extends FormSection {
// Context to read from the parent
constructor(props, context) {
super(props, context);
if (!(context.documentForm instanceof BaseDocumentForm)) {
throw new Error('DocumentSubform must be inside a component within a DocumentForm');
}
}
componentDidMount() {
this.getForm()._registerComponent(this);
}
componentWillUnmount() {
this.getForm()._unregisterComponent(this);
}
getForm() {
return this.context.documentForm;
}
getFieldValue(field) {
// Should use the name as the path prefix!
return this.getForm().getFieldValue(field);
}
setFieldValue(field, value) {
// Should use the name as the path prefix!
this.getForm().setFieldValue(field, value);
}
}
_defineProperty(BaseDocumentSubform, "contextTypes", {
_reduxForm: PropTypes.object,
documentForm: PropTypes.object
});
export default BaseDocumentSubform;
//# sourceMappingURL=BaseDocumentSubform.js.map