I want the answer to a question to appear on the screen for confirmation - reactjs

We are using Material-UI in React to create a web form.
In components / Content.js, case 3: I want to create a confirmation screen that displays the answer to the question below.
I've done a lot of research, but I'm stuck in a situation where I don't know how to implement it.
Can anyone give me some advice?
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
reportWebVitals();
App.js
import "./App.css";
import { Grid } from "#mui/material";
import Header from "./components/Header";
import Content from "./components/Content";
function App() {
return (
<Grid container direction="column">
<Header />
<div style={{ padding: 30 }}>
<Content />
</div>
</Grid>
);
}
export default App;
src / components / contents.js
import React from "react";
import { Grid } from "#mui/material";
import Stepper from "#mui/material/Stepper";
import Step from "#mui/material/Step";
import StepLabel from "#mui/material/StepLabel";
import Button from "#mui/material/Button";
import Typography from "#mui/material/Typography";
import Radio from "#mui/material/Radio";
import RadioGroup from "#mui/material/RadioGroup";
import FormControlLabel from "#mui/material/FormControlLabel";
import FormControl from "#mui/material/FormControl";
import FormLabel from "#mui/material/FormLabel";
import Tooltip from "#mui/material/Tooltip";
import TextField from "#mui/material/TextField";
import InputLabel from "#mui/material/InputLabel";
import Select from "#mui/material/Select";
function getSteps() {
return ["お客様の情報を入力してください", "以下にお答えください", "ご相談ください", "以下の内容をご確認ください"];
}
function getStepContent(stepIndex) {
switch (stepIndex) {
case 0:
return (
<>
{/* <DatePicker views={["year"]} label="Year only" value={selectedDate} onChange={handleDateChange} /> */}
<div>
<FormControl component="fieldset">
<FormLabel component="legend">- 性別 -</FormLabel>
<RadioGroup row aria-label="gender" name="row-radio-buttons-group">
<FormControlLabel value="male" control={<Radio />} label="男性" />
<FormControlLabel value="female" control={<Radio />} label="女性" />
</RadioGroup>
</FormControl>
</div>
<div>
<FormLabel component="legend">- 生年月日 -</FormLabel>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel htmlFor="grouped-native-select">year</InputLabel>
<Select native defaultValue="" id="grouped-native-select" label="Grouping">
<option aria-label="None" value="" />
<optgroup label="year">
{Array.from(Array(2020), (_, num) => (
<option key={num} value={num + 1}>
{num + 1990}
</option>
))}
</optgroup>
</Select>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel htmlFor="grouped-native-select">month</InputLabel>
<Select native defaultValue="" id="grouped-native-select" label="Grouping">
<option aria-label="None" value="" />
<optgroup label="month">
{Array.from(Array(12), (_, num) => (
<option key={num} value={num + 1}>
{num + 1}
</option>
))}
</optgroup>
</Select>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel htmlFor="grouped-native-select">day</InputLabel>
<Select native defaultValue="" id="grouped-native-select" label="Grouping">
<option aria-label="None" value="" />
<optgroup label="day">
{Array.from(Array(31), (_, num) => (
<option key={num} value={num + 1}>
{num + 1}
</option>
))}
</optgroup>
</Select>
</FormControl>
</div>
</>
);
case 1:
return (
<div>
<FormControl component="fieldset">
<FormLabel component="legend">現在、生命保険に加入されていますか?</FormLabel>
<RadioGroup row aria-label="gender" name="row-radio-buttons-group">
<FormControlLabel value="yes" control={<Radio />} label="はい" />
<FormControlLabel value="no" control={<Radio />} label="いいえ" />
</RadioGroup>
<FormLabel component="legend">
現在、入院中ですか。また、3ヶ月以内に医師の診察・検査の結果、入院・手術をすすめられたことがありますか?
</FormLabel>
<RadioGroup row aria-label="gender" name="row-radio-buttons-group">
<FormControlLabel value="yes" control={<Radio />} label="はい" />
<FormControlLabel value="no" control={<Radio />} label="いいえ" />
</RadioGroup>
<FormLabel component="legend">
過去、5年以内に病気やケガで手術を受けたことまたは継続して7日以上の入院をしたことはありますか?
</FormLabel>
<RadioGroup row aria-label="gender" name="row-radio-buttons-group">
<FormControlLabel value="yes" control={<Radio />} label="はい" />
<FormControlLabel value="no" control={<Radio />} label="いいえ" />
</RadioGroup>
</FormControl>
</div>
);
case 2:
return (
<Grid container>
<Grid sm={2} />
<Grid lg={8} sm={8} spacing={10}>
<Tooltip title="ご相談内容を記入することができます" placement="top-start" arrow>
<TextField
label="ご相談内容"
fullWidth
margin="normal"
rows={4}
multiline
variant="outlined"
placeholder="その他ご要望等あれば、ご記入ください"
/>
</Tooltip>
</Grid>
</Grid>
);
case 3:
return (
<div>
<FormControl component="fieldset">
<FormLabel component="legend">- 性別 -</FormLabel>
<FormLabel component="legend">- 生年月日 -</FormLabel>
<FormLabel component="legend">現在、生命保険に加入されていますか?</FormLabel>
<FormLabel component="legend">
現在、入院中ですか。また、3ヶ月以内に医師の診察・検査の結果、入院・手術をすすめられたことがありますか?
</FormLabel>
<FormLabel component="legend">
過去、5年以内に病気やケガで手術を受けたことまたは継続して7日以上の入院をしたことはありますか?
</FormLabel>
<FormLabel component="legend">ご相談内容</FormLabel>
</FormControl>
</div>
);
default:
return "Unknown stepIndex";
}
}
function Content() {
const [activeStep, setActiveStep] = React.useState(0);
const steps = getSteps();
const handleNext = () => {
setActiveStep((prevActiveStep) => prevActiveStep + 1);
};
const handleBack = () => {
setActiveStep((prevActiveStep) => prevActiveStep - 1);
};
const handleReset = () => {
setActiveStep(0);
};
return (
<Grid container>
<Grid sm={2} />
<Grid lg={8} sm={8} spacing={10}>
<Stepper activeStep={activeStep} alternativeLabel>
{steps.map((label) => (
<Step key={label}>
<StepLabel>{label}</StepLabel>
</Step>
))}
</Stepper>
{activeStep === steps.length ? (
<div>
<Typography>全ステップの表示を完了</Typography>
<Button onClick={handleReset}>リセット</Button>
</div>
) : (
<div>
<Typography>{getStepContent(activeStep)}</Typography>
<Button disabled={activeStep === 0} onClick={handleBack}>
戻る
</Button>
<Button variant="contained" color="primary" onClick={handleNext}>
{activeStep === steps.length - 1 ? "送信" : "次へ"}
</Button>
</div>
)}
</Grid>
</Grid>
);
}
export default Content;

Related

Removing Items from an Array When Radio Button in Form is Selected/Form Submitted

I have developed a short questionnaire in React using Material-UI as shown below. I am pulling the questions from a json file I have that looks like the following:
[ {
"id": 1,
"question": "Which section 1 criterion are applicable?"
"criterion": ["1.1", "1.2", "1.3"]
"decision": "Yes"
},
{
"id": 2,
"question": "Which section 2 criterion are applicable?"
"criterion": ["2.1", "2.2", "2.3"]
"decision": "No"
},
...
]
At the start of the questionnaire, all criteria are added to applicableCriteria (shown below). Based on the user's responses, I am trying to remove criterion from applicableCriteria. For example, if the user responds 'Yes' to question 1, the list of criterion shown for the question with id=1 should be removed from applicableCriteria. I have experimented with some different things, but my novice JavaScript skills haven't gotten me far. Below is a working, error-free version of what I've been working with. Any tips on how I should go about this successfully?
import * as React from "react";
import TextField from "#mui/material/TextField";
import {
Button,
Radio,
RadioGroup,
FormControlLabel,
FormControl,
FormLabel,
FormHelperText,
FormGroup,
Checkbox,
Grid,
Box,
} from "#mui/material";
import { useForm } from "react-hook-form";
import Records from "./CriterionQuestions.json";
const QuestionnaireForm = () => {
const {
register,
handleSubmit,
watch,
formState: { errors },
} = useForm();
const onSubmit = (data) => console.log(data);
console.log(errors);
let applicableCriteria = [];
// Push all possible criteria to list
for (let q = 0; q < Records.length; q++) {
for (let c = 0; c < Records[q].criterion.length; c++) {
applicableCriteria.push(Records[q].criterion[c]);
}
}
return (
<div className="App__form">
<h1> Questionnaire </h1>
<h2>{applicableCriteria}</h2>
<form onSubmit={handleSubmit(onSubmit)}>
{/* Radio button */}
<FormControl error={Boolean(errors.question1)}>
<FormLabel component="legend">
{/* {" "}
Is the modification applicable to only fixed-wing and non-commercial
derivative aircraft?{" "} */}
{Records[0].question}
</FormLabel>
<RadioGroup row aria-label="question1" name="question1">
<FormControlLabel
value="yes"
control={
<Radio
{...register("question1", {
required: "Please select a response.",
})}
/>
}
label="Yes"
/>
<FormControlLabel
value="no"
control={
<Radio
{...register("question1", {
required: "Please select a response.",
})}
/>
}
label="No"
/>
</RadioGroup>
<FormHelperText style={{ color: "#d32f2f" }}>
{errors.question1?.message}
</FormHelperText>
</FormControl>
<FormControl error={Boolean(errors.question2)}>
<FormLabel component="legend">{Records[1].question}</FormLabel>
<RadioGroup row aria-label="question2" name="question2">
<FormControlLabel
value="yes"
control={
<Radio
{...register("question2", {
required: "Please select a response.",
})}
/>
}
label="Yes"
/>
<FormControlLabel
value="no"
control={
<Radio
{...register("question2", {
required: "Please select a response.",
})}
/>
}
label="No"
/>
</RadioGroup>
<FormHelperText style={{ color: "#d32f2f" }}>
{errors.question2?.message}
</FormHelperText>
</FormControl>
<div className="clearfix"></div>
<FormControl error={Boolean(errors.question8)}>
<FormLabel component="legend">{Records[7].question}</FormLabel>
<RadioGroup row aria-label="question8" name="question8">
<FormControlLabel
value="yes"
control={
<Radio
{...register("question8", {
required: "Please select a response.",
})}
/>
}
label="Yes"
/>
<FormControlLabel
value="no"
control={
<Radio
{...register("question8", {
required: "Please select a response.",
})}
/>
}
label="No"
/>
</RadioGroup>
<FormHelperText style={{ color: "#d32f2f" }}>
{errors.question8?.message}
</FormHelperText>
</FormControl>
<div className="clearfix"></div>
<FormControl error={Boolean(errors.question9)}>
<FormLabel component="legend">{Records[8].question}</FormLabel>
<RadioGroup row aria-label="question9" name="question9">
<FormControlLabel
value="yes"
control={
<Radio
{...register("question9", {
required: "Please select a response.",
})}
/>
}
label="Yes"
/>
<FormControlLabel
value="no"
control={
<Radio
{...register("question9", {
required: "Please select a response.",
})}
/>
}
label="No"
/>
</RadioGroup>
<FormHelperText style={{ color: "#d32f2f" }}>
{errors.question9?.message}
</FormHelperText>
</FormControl>
<div className="clearfix"></div>
<TextField
id="outlined-basic"
name="modName"
label="Modification Name"
variant="outlined"
fullWidth
{...register("modName", {
required: "Modification Name is required.",
})}
error={Boolean(errors.modName)}
helperText={errors.modName?.message}
/>
{/* Check box */}
<Box sx={{ paddingTop: 3 }} />
<div className="clearfix"></div>
<Button
variant="contained"
color="primary"
type="submit"
className="btns"
>
Submit Responses
</Button>
</form>
</div>
);
};
export default QuestionnaireForm;

how can I change the layout of this material UI form?

I have a checkout form which I made using material UI looking like this:
It seems minor but I'd like to change the layout so that First Name and Last Name etc. are all on the same row, looking more like this (but I'm not sure how to go about it):
Here's the code for my address form component:
return (
<>
<Typography variant="h6" gutterBottom>
Shipping address
</Typography>
<FormProvider {...methods}>
<form
onSubmit={methods.handleSubmit((data) =>
test({
...data,
shippingCountry,
shippingSubdivision,
shippingOption,
})
)}
>
<Grid container spacing={3}>
<FormInput required name="firstName" label="First name" />
<FormInput required name="lastName" label="Last name" />
<FormInput required name="address1" label="Address line 1" />
<FormInput required name="email" label="Email" />
<FormInput required name="city" label="City" />
<FormInput required name="zip" label="Zip / Postal code" />
<Grid item xs={12} sm={6}>
<InputLabel>Shipping Country</InputLabel>
<Select
value={shippingCountry}
fullWidth
onChange={(e) => setShippingCountry(e.target.value)}
>
{Object.entries(shippingCountries)
.map(([code, name]) => ({ id: code, label: name }))
.map((item) => (
<MenuItem key={item.id} value={item.id}>
{item.label}
</MenuItem>
))}
</Select>
</Grid>
<Grid item xs={12} sm={6}>
<InputLabel>Shipping Subdivision</InputLabel>
<Select
value={shippingSubdivision}
fullWidth
onChange={(e) => setShippingSubdivision(e.target.value)}
>
{Object.entries(shippingSubdivisions)
.map(([code, name]) => ({ id: code, label: name }))
.map((item) => (
<MenuItem key={item.id} value={item.id}>
{item.label}
</MenuItem>
))}
</Select>
</Grid>
<Grid item xs={12} sm={6}>
<InputLabel>Shipping Options</InputLabel>
<Select
value={shippingOption}
fullWidth
onChange={(e) => setShippingOption(e.target.value)}
>
{shippingOptions
.map((sO) => ({
id: sO.id,
label: `${sO.description} - (${sO.price.formatted_with_symbol})`,
}))
.map((item) => (
<MenuItem key={item.id} value={item.id}>
{item.label}
</MenuItem>
))}
</Select>
</Grid>
</Grid>
<br />
<div style={{ display: "flex", justifyContent: "space-between" }}>
<Button component={Link} variant="outlined" to="/cart">
Back to Cart
</Button>
<Button type="submit" variant="contained" color="primary">
Next
</Button>
</div>
</form>
</FormProvider>
</>
);
};
And my custom text field component:
import React from "react";
import { TextField, Grid } from "#material-ui/core";
import { useFormContext, Controller } from "react-hook-form";
const FormInput = ({ name, label, required }) => {
const { control } = useFormContext();
const isError = false;
return (
<>
<Controller
control={control}
name={name}
render={({ field }) => <TextField fullWidth label={label} required />}
/>
</>
);
};
export default FormInput;
Looks like you're already using Mui Grid so I think you need to place your <FormInput/> components within a <Grid item/> component. Like this:
<Grid container>
<Grid container direction="row">
<Grid item xs={6} sm={6}>
<FormInput required name="firstName" label="First name" />
</Grid>
<Grid item xs={6} sm={6}>
<FormInput required name="lastName" label="Last name" />
</Grid>
</Grid>
...Another Grid row, and so on...
</Grid>

What is the flow of control?

I am not understanding the flow of control since I am a newbie. In this code, after the component is rendered, useEffects get called. When the first useEffect is called, it is dispatching an action. So, after the action is dispatched, it should re-render the component because I am fetching the change in state from useSelector. Instead, it is executing the second useEffect. Similar is the case with the third useEffect, after it is triggered, it is changing the formData which is in useState. Instead of re-rendering, it is executing the 4th useEffect. Can anyone please help me understand the flow right from the start to the end?
import React,{useState,useEffect,useRef} from "react";
import AdminLayout from "../../../hoc/adminLayout";
import {useFormik,FieldArray,FormikProvider} from "formik";
import {useDispatch,useSelector} from "react-redux";
import {validation,formValues} from "./validationSchema";
import {getAdminArticle,updateArticle} from "../../../store/actions/articles_actions";
import {clearCurrentArticle} from "../../../store/actions/index";
import Loader from "../../../utils/loader";
import {
TextField,
Button,
Divider,
Chip,
Paper,
InputBase,
IconButton,
Select,
MenuItem,
FormControl,
FormHelperText
} from '#material-ui/core';
import AddIcon from '#material-ui/icons/Add';
import WYSIWYG from "../../../utils/forms/wysiwyg";
const EditArticle=(props)=>{
const dispatch=useDispatch();
const notifications=useSelector((state)=>{
return state.notifications;
})
const articles=useSelector((state)=>{
return state.articles;
})
const [isLoading, setIsLoading]=useState(true);
const [editorBlur,setEditorBlur]=useState(false);
const [formData,setFormData]=useState(formValues);
const actorsValue=useRef("");
/////edit/////
const [editContent,setEditContent]=useState(null);
////edit////
const formik=useFormik({
enableReinitialize:true,
initialValues:formData,
validationSchema:validation,
onSubmit:(values,{resetForm})=>{
//console.log(values);
setIsLoading(true);
dispatch(updateArticle(values,props.match.params.id));
}
});
const handleEditorState=(state)=>{
formik.setFieldValue("content",state,true);
}
const handleEditorBlur=(blur)=>{
setEditorBlur(true);
}
const errorHelper=(formik,value)=>{
return {
error:formik.errors[value] && formik.touched[value]? true:false,
helperText:formik.errors[value] && formik.touched[value]?formik.errors[value]:null
}
}
///////edit/////////
useEffect(()=>{
console.log("first");
dispatch(getAdminArticle(props.match.params.id));
},[dispatch,props.match.params])
/////edit///////
useEffect(()=>{
console.log("second");
// if(notifications && notifications.success){
// props.history.push("/dashboard/articles");
// }
// if(notifications && notifications.error){
setIsLoading(false);
// }
},[notifications,props.history])
useEffect(()=>{
console.log("third");
if(articles && articles.current){
setFormData(articles.current);
setEditContent(articles.current.content);
}
},[articles])
useEffect(()=>{
console.log("unmounted");
return ()=>{
dispatch(clearCurrentArticle());
}
},[dispatch])
return <AdminLayout section="Add Article">
{console.log("rendered")}
{isLoading?<Loader />:<form className="mt-3 article_form" onSubmit={formik.handleSubmit}>
<div className="form-group">
<TextField
style={{width:"100%"}}
name="title"
label="Enter a title"
variant="outlined"
{...formik.getFieldProps("title")}
{...errorHelper(formik,"title")}
/>
</div>
<div className="form-group">
<WYSIWYG setEditorState={(state)=>{
return handleEditorState(state)
}} setEditorBlur={(blur)=>{
return handleEditorBlur(blur)
}}
editContent={editContent}
/>
{formik.errors.content && editorBlur?
<FormHelperText error={true}>
{formik.errors.content}
</FormHelperText> :null}
<TextField
type="hidden"
name="content"
{...formik.getFieldProps("content")}
/>
</div>
<div className="form-group">
<TextField
style={{width:"100%"}}
name="excerpt"
label="Enter an excerpt"
variant="outlined"
{...formik.getFieldProps("excerpt")}
{...errorHelper(formik,"excerpt")}
multiline
rows={4}
/>
</div>
<Divider className="mt-3 mb-3" />
<h5>Movie Data and Score</h5>
<div className="form-group">
<TextField
style={{width:"100%"}}
name="score"
label="Enter an score"
variant="outlined"
{...formik.getFieldProps("score")}
{...errorHelper(formik,"score")}
/>
</div>
<FormikProvider value={formik}>
<h5>Add the Actors</h5>
<FieldArray name="actors"
render={
arrayhelpers=>(
<div>
<Paper className="actors_form">
<InputBase
className="input"
placeholder="Add actor name here"
inputRef={actorsValue}
/>
<IconButton onClick={()=>{
arrayhelpers.push(actorsValue.current.value);
actorsValue.current.value="";
}}>
<AddIcon />
</IconButton>
</Paper>
{formik.errors.actors && formik.touched.actors?
<FormHelperText error={true}>
{formik.errors.actors}
</FormHelperText> :null}
<div className="chip_container">
{formik.values.actors.map((actor,index)=>{
return <div key={actor}>
<Chip label={`${actor}`} color="primary" onDelete={()=>{
return arrayhelpers.remove(index);
}}>
</Chip>
</div>
})}
</div>
</div>
)
}
/>
</FormikProvider>
<div className="form-group">
<TextField
style={{width:"100%"}}
name="score"
label="Enter the Director"
variant="outlined"
{...formik.getFieldProps("director")}
{...errorHelper(formik,"director")}
/>
</div>
<FormControl variant="outlined" >
<h5>Select a Status</h5>
<Select
name="status"
{...formik.getFieldProps("status")}
error={formik.errors.status && formik.touched.status? true:false}
>
<MenuItem value=""><em>None</em></MenuItem>
<MenuItem value="draft">Draft</MenuItem>
<MenuItem value="public">Public</MenuItem>
</Select>
{formik.errors.status && formik.touched.status?
<FormHelperText error={true}>
{formik.errors.status}
</FormHelperText> :null}
</FormControl>
<Divider className="mt-3 mb-3" />
<Button variant="contained" color="primary" type="submit" >
Edit Article
</Button>
</form>
}
</AdminLayout>
}
export default EditArticle;
[enter image description here][1]

Can't .map for a material RadioGroup

I have:
const documentTypes = [
'General',
'Email',
'Fiction story',
'Blog post',
'Newsletter',
'Review',
'Website content'
]
and
<FormControl component="fieldset">
<FormLabel component="legend">Document Type</FormLabel>
<RadioGroup name="documentType" value={docType} onChange={handleChangeDoc}>
{documentTypes.map((documentType, idx) => {
<FormControlLabel value={documentType} control={<Radio />} label={documentType} key={idx} />
})}
<FormControlLabel value="other" control={<Radio />} label={<Input onFocus={() => setDocType('other')} />} />
</RadioGroup>
</FormControl>
but I don't see all of the options. Just the other. What am I doing wrong?
This is with material-ui for react.
I think you only need to return the FormControlLabel in the map.
Options 1) remove the {} around the FormControlLabel
<FormControl component="fieldset">
<FormLabel component="legend">Document Type</FormLabel>
<RadioGroup name="documentType" value={docType} onChange={handleChangeDoc}>
{documentTypes.map((documentType, idx) =>
<FormControlLabel value={documentType} control={<Radio />} label={documentType} key={idx} />
)}
<FormControlLabel value="other" control={<Radio />} label={<Input onFocus={() => setDocType('other')} />} />
</RadioGroup>
</FormControl>
Option 2) Just add return before FormControlLabel
<FormControl component="fieldset">
<FormLabel component="legend">Document Type</FormLabel>
<RadioGroup name="documentType" value={docType} onChange={handleChangeDoc}>
{documentTypes.map((documentType, idx) => {
return <FormControlLabel value={documentType} control={<Radio />} label={documentType} key={idx} />
})}
<FormControlLabel value="other" control={<Radio />} label={<Input onFocus={() => setDocType('other')} />} />
</RadioGroup>
</FormControl>

Material UI select and autocomplete box not lined up

Screenshot of misaligned drop-down boxes
Hi! I'm a beginner ReactJS engineer. I added 2 drop-down boxes from material UI, the left box is the Autocomplete from materialui/labs and the right box is the Select from materialui/core. They're both placed in the same component with the same styling applied to it, but the Autocomplete is slightly off. Is there a simple fix to this misalignment?
<AutocompleteComponent
formStyle={{ width: 200 }}
label={'Build'}
options={builds}
value={selectedBuild}
handleChange={handleFilterSelectChange('selectedBuild')} />
<SelectComponent
formStyle={{ width: 120 }}
label={'Sheet Layout'}
options={sheetLayouts}
value={selectedSheetLayout}
handleChange={handleFilterSelectChange('selectedSheetLayout')} />
For select component:
const SelectComponent = props => {
return (
<FormControl
className={className}
required={required}
error={error}
margin={margin}
style={formStyle}
>
<InputLabel>{label}</InputLabel>
<Select
inputRef={inputRef}
value={value}
style={style}
onChange={handleChange}
disabled={disabled}
onClick={onClick}
onFocus={onFocus}
onBlur={onBlur}
>
{excludeNone ? null : (
<MenuItem value="">
<em>{noneLabel ? noneLabel : "None"}</em>
</MenuItem>
)}
{optionsExist(options)}
</Select>
{helperText ? <FormHelperText>{helperText}</FormHelperText> : null}
</FormControl>
);
};
For the autocomplete component:
class AutocompleteComponent extends React.Component {
render() {
return (
<FormControl
className={className}
required={required}
error={error}
margin={margin}
style={formStyle}
>
<Autocomplete
style={style}
disabled={disabled}
onClick={onClick}
onFocus={onFocus}
onBlur={onBlur}
options={options}
getOptionLabel= {option => option.label && option.label.toString()}
id="auto-complete"
autoComplete
includeInputInList
renderInput={params => (
<TextField
{...params}
label="Builds"
margin="normal"
fullWidth
position="center"
/>
)}
renderOption={(option, { inputValue }) => {
const matches = match(option.label, inputValue);
const parts = parse(option.label, matches);
return (
<div>
{parts.map((part, index) => (
<span
key={index}
style={{ fontWeight: part.highlight ? 700 : 400 }}
>
{part.text}
</span>
))}
</div>
);
}}
/>
{helperText ? <FormHelperText>{helperText}</FormHelperText> : null}
</FormControl>
);
}
}
Thanks!

Resources