6

ドロップダウン値が のときに新しいテキスト フィールドが必要ですが、 が新しいテキスト フィールドに値を入れてothersいるため、変数を変更する必要があります。この場合、両方の変数をどこでどのように等しくするのですか?building_typeothers

import React from 'react'
import { connect } from 'react-redux'
import { reduxForm } from 'redux-form'
import { StandardForm, TextField, UsStatesSelectField, SelectField } from './../forms'
import { loadProperty, saveProperty } from './../../models/properties'

const validate = values => {
    const required = value => value ? null : 'Required'
    const errors = {}
    errors.name = required(values.name)
    errors.street_address = required(values.street_address)
    errors.city = required(values.city)
    errors.state = required(values.state)
    errors.zip = required(values.zip)
    errors.building_type = required(values.building_type)

    return errors
}

const PropertyInfoForm = reduxForm({
    form: 'propertyInfo',
    fields: ['name', 'street_address', 'city', 'state', 'zip', 'building_type', 'building_other_type'],
    validate
})(React.createClass({
    render() {
        return (
            <StandardForm {...this.props} title="Property Info" resetButton="Reset">
                <TextField {...this.props.fields.name} label="Property Name" />
                <TextField {...this.props.fields.street_address} label="Property    Address" />
                <div className="three fields">
                    <TextField {...this.props.fields.city} label="City" />
                    <UsStatesSelectField {...this.props.fields.state} label="State" />
                    <TextField {...this.props.fields.zip} label="Zip Code" />
                </div>
                <SelectField {...this.props.fields.building_type}
                    label="Please select a Building Type for the junctionbox"
                    options={[
                        ['office', 'Office'],
                        ['private_home', 'Private Home'],
                        ['residential', 'Residential'],
                        ['retail', 'Retail'],
                        ['restaurant', 'Restaurant'],
                        ['school', 'School'],
                        ['townhouse', 'Townhouse'],
                        ['warehouse', 'Warehouse'],
                        ['other', 'Other']
                    ]}
                />
                {((this.props.fields.building_type.value) === 'other') ? (
                    <TextField {...this.props.fields.building_other_type} label="Please Specify Other Building Type" />
                ) : ''}
            </StandardForm>
        )
    }
}))

export default connect(
    (state, ownProps) => ({
        property: state.entities.property[ownProps.params.propertyId]
    }),
    dispatch => ({
        dispatch
    })
)(({ dispatch, property }) => (
    <PropertyInfoForm
        initialValues={property}
        onSubmit={(values) => dispatch(saveProperty(property.id, values)).then(_ => dispatch(loadProperty(property.id)))}
    />
))
4

1 に答える 1