我有一个renderSelectField作为
const renderSelectField = ({ input, label, meta: { touched, error }, children, ...custom }) => (
<SelectField
errorText={touched && error}
{...input}
onBlur={(event, index, value) => input.onBlur(value)}
onChange={(event, index, value) => {
input.onChange(value);
}}
children={children}
{...custom}
/>
);
和带有两个select字段的from。当两个字段都被选中时,我想触发一些动作,这里我们有getMappedRooms()。 但是,当我选择一个字段(roomType)然后选择另一个字段(floorNumber)时,先前字段中的值消失了。
我该如何处理这种情况?
<form>
<Field
name="roomType"
component={renderSelectField}
hintText="Select Room Type"
fullWidth
onChange={(event, index) => {
getMappedRooms('e', index, floorNumberValue);
}}
>
{
roomTypes.map((roomType, i) => (
<MenuItem key={i} value={roomType} primaryText={`Room Type : ${roomType.roomType || roomTypeValue.roomType}`} />
))
}
</Field>
<Field
name="floorNumber"
component={renderSelectField}
onChange={(event, index) => {
getMappedRooms('e', roomTypeValue, index);
}}
>
{
[...Array(numberOfFloors).keys()].map((floorNumber, i) => (
<MenuItem key={i} value={floorNumber + 1} primaryText={`Floor No : ${floorNumber + 1}`} />
))
}
</Field>
</form>