import React from 'react'; import FileSelector from './file-selector.js'; import { Icon } from './common.js'; var formFieldCounter = 0, formFieldFileSelectorTypes = ['file', 'directory'], formFieldNestedLabelTypes = ['radio', 'checkbox']; function formFieldId() { return 'form-field-' + ++formFieldCounter; } export class FormField extends React.Component { 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 (formFieldFileSelectorTypes.includes(this.props.type)) { this._element = 'input'; this._type = 'hidden'; } else { // Non field, e.g.