import React, { PropTypes, Component } from 'react'; import Formsy from 'formsy-react'; import { Button } from 'react-bootstrap'; import FormComponent from "./FormComponent.jsx"; import Utils from './utils.js'; class NewDocument extends Component { constructor() { super(); this.submitForm = this.submitForm.bind(this); this.state = { disabled: false, errors: [] }; } submitForm(data) { this.setState({disabled: true}); // if there's a submit callback, run it if (this.props.submitCallback) { this.props.submitCallback(); } // remove any empty properties let document = _.compactObject(Utils.flatten(data)); const collection = this.props.collection; // add prefilled properties if (this.props.prefilledProps) { document = Object.assign(document, this.props.prefilledProps); } Meteor.call(this.props.methodName, document, (error, document) => { this.setState({disabled: false}); if (error) { console.log(error) this.setState({ errors: [{ content: error.message, type: "error" }] }); if (this.props.errorCallback) { this.props.errorCallback(document, error); } } else { this.setState({errors: []}); this.refs.newDocumentForm.reset(); if (this.props.successCallback) { this.props.successCallback(document); } if (this.context.closeCallback) { this.context.closeCallback(); } } }); } renderErrors() { Flash = Telescope.components.Flash; return