From c1064126914104b407ff25a5f110db23cce97d9a Mon Sep 17 00:00:00 2001 From: Llewellyn D'souza Date: Tue, 8 Feb 2022 18:10:03 +0530 Subject: [PATCH] Fixed: Multiple select form component --- src/pages/editWarehouseDetails/index.js | 40 +++++++++++-------------- src/pages/newWarehouseDetails/index.js | 38 +++++++++++------------ 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/pages/editWarehouseDetails/index.js b/src/pages/editWarehouseDetails/index.js index c1dc0f0..f78269d 100644 --- a/src/pages/editWarehouseDetails/index.js +++ b/src/pages/editWarehouseDetails/index.js @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { useDispatch } from 'react-redux'; -import { Box, Grid, MenuItem, OutlinedInput, Chip } from '@mui/material'; +import { Box, Grid, MenuItem, OutlinedInput, Chip, Select } from '@mui/material'; import { makeStyles } from '@mui/styles'; import DashboardNavbar from 'components/DashboardNavbar'; import DashboardLayout from 'layouts/DashboardLayout'; @@ -24,18 +24,7 @@ const useStyles = makeStyles({ const previewImg = [1, 2, 3]; -const names = [ - 'Oliver Hansen', - 'Van Henry', - 'April Tucker', - 'Ralph Hubbard', - 'Omar Alexander', - 'Carlos Abbott', - 'Miriam Wagner', - 'Bradley Wilkerson', - 'Virginia Andrews', - 'Kelly Snyder' -]; +const inventoryTypes = ['Perishable', 'Material', 'Product', 'Inventory', 'Fleet']; function EditWarehouseDetails() { const classes = useStyles(); @@ -56,7 +45,7 @@ function EditWarehouseDetails() { initialValues: { warehousename: location.state.name, address: location.state.address, - inventorytype: '', + inventorytype: [], attributes: '' }, validationSchema: schema.warehouseForm, @@ -139,15 +128,13 @@ function EditWarehouseDetails() { Types of inventories hosted - } + input={} value={formik.values.inventorytype} error={formik.touched.inventorytype && Boolean(formik.errors.inventorytype)} helperText={formik.touched.inventorytype && formik.errors.inventorytype} @@ -159,17 +146,26 @@ function EditWarehouseDetails() { )} MenuProps={MenuProps} - onChange={formik.handleChange} + onChange={(event) => { + const { + target: { value } + } = event; + formik.setFieldValue( + 'inventorytype', + // On autofill we get a stringified value. + typeof value === 'string' ? value.split(',') : value + ); + }} > - No Selected // Or Empty + None Selected - {names.map((name) => ( + {inventoryTypes.map((name) => ( {name} ))} - + diff --git a/src/pages/newWarehouseDetails/index.js b/src/pages/newWarehouseDetails/index.js index 602699e..192ddab 100644 --- a/src/pages/newWarehouseDetails/index.js +++ b/src/pages/newWarehouseDetails/index.js @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { useDispatch } from 'react-redux'; -import { Box, Grid, MenuItem, OutlinedInput, Chip } from '@mui/material'; +import { Box, Grid, MenuItem, OutlinedInput, Chip, Select } from '@mui/material'; import { makeStyles } from '@mui/styles'; import DashboardNavbar from 'components/DashboardNavbar'; import DashboardLayout from 'layouts/DashboardLayout'; @@ -24,18 +24,7 @@ const useStyles = makeStyles({ const previewImg = [1, 2, 3]; -const names = [ - 'Oliver Hansen', - 'Van Henry', - 'April Tucker', - 'Ralph Hubbard', - 'Omar Alexander', - 'Carlos Abbott', - 'Miriam Wagner', - 'Bradley Wilkerson', - 'Virginia Andrews', - 'Kelly Snyder' -]; +const inventoryTypes = ['Perishable', 'Material', 'Product', 'Inventory', 'Fleet']; function NewWarehouseDetails() { const classes = useStyles(); @@ -56,7 +45,7 @@ function NewWarehouseDetails() { initialValues: { warehousename: '', address: '', - inventorytype: '', + inventorytype: [], attributes: '' }, validationSchema: schema.warehouseForm, @@ -140,13 +129,13 @@ function NewWarehouseDetails() { Types of inventories hosted - } + input={} value={formik.values.inventorytype} error={formik.touched.inventorytype && Boolean(formik.errors.inventorytype)} helperText={formik.touched.inventorytype && formik.errors.inventorytype} @@ -158,17 +147,26 @@ function NewWarehouseDetails() { )} MenuProps={MenuProps} - onChange={formik.handleChange} + onChange={(event) => { + const { + target: { value } + } = event; + formik.setFieldValue( + 'inventorytype', + // On autofill we get a stringified value. + typeof value === 'string' ? value.split(',') : value + ); + }} > - No Selected // Or Empty + None Selected - {names.map((name) => ( + {inventoryTypes.map((name) => ( {name} ))} - +