import React from 'react'; import PropTypes from 'prop-types'; import {Row, LineInput, Input} from './'; import {KEYCODES} from '../../../contacts/constants'; import {isEmpty, get, set} from 'lodash'; import {gettext} from 'core/utils'; export class MultiTextInput extends React.Component { static propTypes: any; static defaultProps: any; errorMessage: any; constructor(props) { super(props); this.state = { touched: {}, }; this.onBlur = this.onBlur.bind(this); this.isFieldInvalid = this.isFieldInvalid.bind(this); this.errorMessage = ''; } onBlur(e) { const _touched = this.state.touched; set(_touched, e.target.name, true); this.setState({touched: _touched}); } isFieldInvalid(field, value, errors) { this.errorMessage = get(this.state.touched, field, false) && isEmpty(value) ? gettext('This field is required.') : errors[field] || ''; return !isEmpty(this.errorMessage); } render() { const {value, field, remove, onChange, label, readOnly, errors, ...props} = this.props; return ( {label && } {!readOnly && (
{ if (event && event.keyCode === KEYCODES.ENTER) { event.preventDefault(); remove(); } }} >
) }
); } } MultiTextInput.propTypes = { remove: PropTypes.func, field: PropTypes.string, type: PropTypes.string, value: PropTypes.string, label: PropTypes.string, onChange: PropTypes.func, readOnly: PropTypes.bool, errors: PropTypes.object, }; MultiTextInput.defaultProps = { readOnly: false, value: '', type: 'text', };