import _ from 'lodash' import Select2 from 'react-select2-wrapper' import React, { Component } from 'react' import PropTypes from 'prop-types' export default class CustomFieldsInputs extends Component { constructor(props) { super(props) } options(cf){ if(cf.options){ return cf.options } return { default: "" } } listInput(cf){ return( { return {id: k, text: (v.length > 0 ? v : '\u00A0')} })} ref={'custom_fields.' + cf.code} className='form-control' defaultValue={cf.value || this.options(cf).default} disabled={this.props.disabled} options={{ theme: 'bootstrap', width: '100%' }} onSelect={(e) => this.props.onUpdate(cf.code, e.params.data.id) } /> ) } stringInput(cf){ return( {this.props.onUpdate(cf.code, e.target.value); this.forceUpdate()} } /> ) } integerInput(cf){ return( {this.props.onUpdate(cf.code, e.target.value); this.forceUpdate()} } /> ) } render() { return (
{_.map(this.props.values, (cf, code) =>
{this[cf.field_type + "Input"](cf)}
)}
) } } CustomFieldsInputs.propTypes = { onUpdate: PropTypes.func.isRequired, values: PropTypes.object.isRequired, disabled: PropTypes.bool.isRequired }