/** * * Input * */ import React from 'react'; import { get, isEmpty, map, isObject } from 'lodash'; import { FormattedMessage } from 'react-intl'; import styles from './styles.scss'; class Input extends React.Component { // eslint-disable-line react/prefer-stateless-function constructor(props) { super(props); this.state = { errors: [], hasInitialValue: false, }; } componentDidMount() { // Init the select value if type === "select" if (this.props.type === 'select' && !isEmpty(this.props.selectOptions) && this.props.selectOptions[0].value !== '') { const target = { name: this.props.target, value: this.props.selectOptions[0].value }; this.props.handleChange({ target }); } } componentWillReceiveProps(nextProps) { if (this.props.type === 'select' && this.props.selectOptionsFetchSucceeded !== nextProps.selectOptionsFetchSucceeded && nextProps.selectOptions[0].value !== '') { const target = { name: nextProps.target, value: nextProps.selectOptions[0].value }; this.props.handleChange({ target }); } } handleChangeCheckbox = (e) => { const target = { type: e.target.type, value: !this.props.value, name: e.target.name, }; this.props.handleChange({ target }); } renderErrors = (errorStyles) => { // eslint-disable-line consistent-return if (!this.props.noErrorsDescription) { const divStyle = errorStyles || styles.errorContainer; return ( map(this.state.errors, (error, key) => { const displayError = isObject(error) && error.id ? : error; return (
{displayError}
); }) ); } } renderInputCheckbox = (requiredClass, inputDescription) => { const title = !isEmpty(this.props.title) ?
: ''; const spacer = !inputDescription ?
:
; return (
{title} {(message) => ( )}
{inputDescription}
{spacer}
) } renderInputSelect = (bootStrapClass, requiredClass, inputDescription) => { const spacer = !isEmpty(this.props.inputDescription) ?
:
; return (
{inputDescription}
{spacer}
); } renderInputTextArea = (bootStrapClass, requiredClass, bootStrapClassDanger, inputDescription) => { let spacer = !isEmpty(this.props.inputDescription) ?
:
; if (!this.props.noErrorsDescription && !isEmpty(this.state.errors)) { spacer =
; } return (
{(placeholder) => (