import React from "react"; import FileSelector from "component/file-selector.js"; import SimpleMDE from "react-simplemde-editor"; import { formFieldNestedLabelTypes, formFieldId } from "../form"; import style from "react-simplemde-editor/dist/simplemde.min.css"; const formFieldFileSelectorTypes = ["file", "directory"]; class FormField extends React.PureComponent { static propTypes = { type: React.PropTypes.string.isRequired, prefix: React.PropTypes.string, postfix: React.PropTypes.string, hasError: React.PropTypes.bool, trim: React.PropTypes.bool, regexp: React.PropTypes.oneOfType([ React.PropTypes.instanceOf(RegExp), React.PropTypes.string, ]), }; static defaultProps = { trim: false, }; constructor(props) { super(props); this._fieldRequiredText = __("This field is required"); this._type = null; this._element = null; this._extraElementProps = {}; this.state = { isError: null, errorMessage: null, }; } componentWillMount() { if (["text", "number", "radio", "checkbox"].includes(this.props.type)) { this._element = "input"; this._type = this.props.type; } else if (this.props.type == "text-number") { this._element = "input"; this._type = "text"; } else if (this.props.type == "SimpleMDE") { this._element = SimpleMDE; this._type = "textarea"; this._extraElementProps.options = { placeholder: this.props.placeholder, hideIcons: ["guide", "heading", "image", "fullscreen", "side-by-side"], }; } else if (formFieldFileSelectorTypes.includes(this.props.type)) { this._element = "input"; this._type = "hidden"; } else { // Non field, e.g.