So this might sound a bit confusing but I want to get a string to make a call with an api. I want to do it in a form with multiple checkboxes. The original code will look like:
let value = "1"
so if a user clicks the number 28 check box. the string will become:
"1,28"
if the user also checks 5 the string will be:
1,28,5
If the user decides to uncheck 28 while leaving 5 checked the string will become:
1,5
That's basically the long and short of it.
I'm using React to do this project.
Edit:
This is the code for the React Dialog box with the options.
import React, { useState, useEffect } from 'react';
import { Dialog, DialogTitle, DialogContent, makeStyles } from '@material-ui/core';
import { Button, ButtonToolbar } from 'react-bootstrap';
import Grid from '@material-ui/core/Grid';
import * as FaIcons from 'react-icons/fa';
import './FilterPopup.css'
import { filterData } from './filterData';
import { genresData } from './genresData'
export default function Filter(props) {
const { title, children, openPopup, setOpenPopup } = props;
const [filtergenres, setFilterGenres] = useState()
return (
<Dialog open={openPopup} className='filterDialog' maxWidth="md">
<DialogTitle>
<div className='popupTitle'> Filter </div>
<Button className='popupCloseBtn' onClick={() => { setOpenPopup(false) }}>
<FaIcons.FaTimes />
</Button>
</DialogTitle>
<DialogContent dividers>
<form className='pop-up-forms'>
<label className='popuppart'>
Sort By:
<select className='filter-sort'>
{filterData.map((item, index) => {
return (
<option key={index} value={item.value}>{item.title}</option>
)
})}
</select>
<Button className='popupSearchSubmitBtn' onClick={() => { }}>
submit
</Button>
</label>
<label className='popuppart'>
Include Adult:
<input
className='filterchkbox'
name="isAdult"
type="checkbox" />
</label>
<label className='filterGenres'>
Genres:
<Grid container spacing={1} direction="row" justify="center" alignItems="center">
{genresData.map((item, index) => {
return (
<Grid item xs={1.5} key={index}>
<label className='genresLabel'>
{item.title}
<input
className='filterchkbox'
name="isAdult"
type="checkbox" />
</label>
</Grid>
)
})}
</Grid>
</label>
</form>
</DialogContent>
</Dialog >
)
}
and here is a screenshot of what it looks like in a browser.
