import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import FRC from 'formsy-react-components'; import { intlShape } from 'meteor/vulcan:i18n'; import DateTime from './DateTime.jsx'; import classNames from 'classnames'; import Flash from './Flash.jsx'; // import Utils from './utils.js'; const Checkbox = FRC.Checkbox; const CheckboxGroup = FRC.CheckboxGroup; const Input = FRC.Input; const RadioGroup = FRC.RadioGroup; const Select = FRC.Select; const Textarea = FRC.Textarea; class FormComponent extends PureComponent { constructor(props) { super(props); this.handleBlur = this.handleBlur.bind(this); this.updateCharacterCount = this.updateCharacterCount.bind(this); this.renderErrors = this.renderErrors.bind(this); if (props.limit) { this.state = { limit: props.value ? props.limit - props.value.length : props.limit } } } componentWillReceiveProps(nextProps) { this.updateCharacterCount(nextProps.name, nextProps.value) } handleBlur() { // see https://facebook.github.io/react/docs/more-about-refs.html if (this.formControl !== null) { this.props.updateCurrentValues({[this.props.name]: this.formControl.getValue()}); } } updateCharacterCount(name, value) { if (this.props.limit) { const characterCount = value ? value.length : 0; this.setState({ limit: this.props.limit - characterCount }); } } renderComponent() { // see https://facebook.github.io/react/warnings/unknown-prop.html const { control, group, updateCurrentValues, document, beforeComponent, afterComponent, limit, errors, ...rest } = this.props; // eslint-disable-line // const base = typeof this.props.control === "function" ? this.props : rest; const properties = { value: '', // default value, will be overridden by `rest` if real value has been passed down through props ...rest, onBlur: this.handleBlur, ref: (ref) => this.formControl = ref, }; // if control is a React component, use it if (typeof this.props.control === "function") { return } else { // else pick a predefined component switch (this.props.control) { case "number": return ; case "url": return ; case "email": return ; case "textarea": return