import React from "react"; import PropTypes from "prop-types"; 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: PropTypes.string.isRequired, prefix: PropTypes.string, postfix: PropTypes.string, hasError: PropTypes.bool, trim: PropTypes.bool, regexp: PropTypes.oneOfType([ PropTypes.instanceOf(RegExp), 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: ["heading", "image", "fullscreen", "side-by-side"], }; } else if (formFieldFileSelectorTypes.includes(this.props.type)) { this._element = "input"; this._type = "hidden"; } else { // Non field, e.g.