import React from "react"; import FileSelector from "./file-selector.js"; import { Icon } from "./common.js"; import SimpleMDE from "react-simplemde-editor"; import style from "react-simplemde-editor/dist/simplemde.min.css"; var formFieldCounter = 0, formFieldFileSelectorTypes = ["file", "directory"], formFieldNestedLabelTypes = ["radio", "checkbox"]; function formFieldId() { return "form-field-" + ++formFieldCounter; } export class FormField extends React.PureComponent { static propTypes = { type: React.PropTypes.string.isRequired, prefix: React.PropTypes.string, postfix: React.PropTypes.string, hasError: React.PropTypes.bool, }; constructor(props) { super(props); this._fieldRequiredText = __("This field is required"); this._type = null; this._element = null; 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"; } else if (formFieldFileSelectorTypes.includes(this.props.type)) { this._element = "input"; this._type = "hidden"; } else { // Non field, e.g.