samedi 6 mars 2021

How can I get the proper value of my checkbox instead of Null?

Currently I'm building a product page that has multiple filters in it. I want to get the value of my checkbox when it is checked by the user so I can display my code when checked. Have added a console.log to check it but only returns the error that it cannot read property of Null. What am I doing wrong?

My HTML

<h4>Some title</h4>
        <label class="container-filter">15 - 30 min.
                <input type="checkbox" value="15">
                <span class="checkmark"></span>
              </label>
        <label class="container-filter">30 - 60 min.
                <input type="checkbox" value="30">
                <span class="checkmark"></span>
              </label>

My Javascript

var input = document.querySelectorAll("input");
inputs.forEach(item => {
    item.addEventListener('change', function() {
    var checkedValue =  document.querySelector('.boardgame:checked').value;
        console.log(checkedValue)
 });
});



How can I get the proper value of my checkbox instead of Null?

Currently I'm building a product page that has multiple filters in it. I want to get the value of my checkbox when it is checked by the user so I can display my code when checked. Have added a console.log to check it but only returns the error that it cannot read property of Null. What am I doing wrong?

My HTML

<h4>Some title</h4>
        <label class="container-filter">15 - 30 min.
                <input type="checkbox" value="15">
                <span class="checkmark"></span>
              </label>
        <label class="container-filter">30 - 60 min.
                <input type="checkbox" value="30">
                <span class="checkmark"></span>
              </label>

My Javascript

var input = document.querySelectorAll("input");
inputs.forEach(item => {
    item.addEventListener('change', function() {
    var checkedValue =  document.querySelector('.boardgame:checked').value;
        console.log(checkedValue)
 });
});



Checkbox does not change its appearance when clicked

I'm working on a kivy application and I'd like to save checkbox state in json and display it when it runs. Unfortunately, when the starting value is True, and i click on a checkbox to turn it to False it does not change its appereance to unchecked despite displaying it correctly in a console with a print statement. When the starting value is False it works just fine.

python code:

class settings(Screen):
    
    with open('settings.json') as f:
        data = json.load(f)

    skipbool=data['skiplogin']
    
    def skiplogin_click(self, instance, value):
        if value is True: 
            print("yes") 
        else: 
            print("no") 
    pass

kv code:

<settings>:
    name: "screen_settings"
    GridLayout:
    
        cols: 2
        rows: 1
        Label:
            text: 'skip'
        
        CheckBox:
            active: root.skipbool
            on_active: root.skiplogin_click(self, self.active)



vendredi 5 mars 2021

My Checkbox isn't working while Im building a Hamburger Button

Im trying to build a nav bar that have hamburger button to open drop down menus. While building the button, the checkbox dont want to be checked. Here is the HTML code :

  body {
  margin: 0px;
  background-image: url("Images/background.jpg");
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  background-position: center;
  font-family: 'Titillium Web', sans-serif;
  height: 100%;
}

.container {
  display: grid;
  grid-template-columns: 1fr;
}

html {
  scroll-behavior: smooth;
}


/*NAV BAR*/

.topbar-wrapper {
  display: flex;
  padding: 0px;
  background-color: teal;
  width: 100%;
  justify-content: space-between;
  align-items: center;
}

.tombol-menu {
  padding: 35px;
}

.tombol-menu .centang {
  position: absolute;
  top: 32px;
  left: 31px;
  cursor: pointer;
  width: 60px;
  height: 60px;
  padding: 35px;
  opacity: 1;
  align-items: center;
  justify-content: center;
  z-index: 4;
}

.tombol-menu .tombol-hamburger {
  position: absolute;
  top: 0;
  left: 0;
  width: 60px;
  height: 60px;
  padding: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tombol-menu .tombol-hamburger>div {
  position: relative;
  width: 100%;
  height: 5px;
  background-color: yellowgreen;
  align-items: center;
  justify-content: center;
}

.tombol-menu .tombol-hamburger>div::before,
.tombol-menu .tombol-hamburger>div::after {
  content: "";
  position: absolute;
  z-index: 1;
  top: -17px;
  width: 100%;
  height: 5px;
  background: inherit;
}

.tombol-menu .tombol-hamburger>div::after {
  top: 17px;
}

.tombol-menu .centang:checked+.tombol-hamburger>div {
  transform: rotate(135deg);
}

.logo-img {
  width: 120px;
}

.tombol-search {
  padding: 35px;
}

.topbar-wrapper>div {
  margin-left: 20px;
  font-size: 1em;
}

.navigasi {
  position: fixed;
  top: 0px;
  bottom: 0px;
  width: 100%;
  height: 100%;
  /*visibility: hidden;*/
  display: flex;
  text-decoration: none;
  justify-content: center;
  align-items: center;
}

.navigasi li {
  list-style: none;
}

.navigasi li a {
  display: block;
  text-decoration: none;
  color: lightcoral;
  padding: 1em;
}

.navigasi li a:hover {
  color: lightseagreen;
<header>
  <div class="topbar-wrapper">
    <div class="tombol-menu">
      <input type="checkbox" class="centang" id="centangID">
      <div class="tombol-hamburger">
        <div>

        </div>
      </div>
    </div>
    <div class="logo">
      <a href="index.html">
        <img class="logo-img" src="LOGO.png" alt="">
      </a>
    </div>
    <div class="tombol-search">
      <a href="">Search</a>
    </div>
  </div>
</header>

I think its because my checkbox is inside some DIV, or my code is purely bad.

PS:Im new to HTML and CSS.




Toggle the check box on and off, and console log the id's of the selected checkboxes. How can i do that?

I am using material UI for UI, and Axios to fetch data as JSON from an API endpoint. I have been successful in sorting/ filtering/ mapping the users the way I want and displaying them on the table. There are 1000 users btw.

on clicking a LI, I would like the checkbox toggle to turn on and off. The ID's of the selected user has to console.log on the console. How can I write such a function? This should work with multiple LI's as well. I can select as many LI's as I want and they should all console.log

PS- as a bonus, I would also like to display the user email when I click a particular checkbox, inside the table. Toggle it on/ off Should I use Checkbox from the material-UI library, and use an onChange to show the {user.email} in a styledTableCell component?

so how about I write a state?

const [showEmail, setShowEmail]= useState(false);
const handleClick=()=>{
showMe= !this.state.showMe
}

on onChange i want to show {user.email} In a styledtablecell, so..

onChange={()=> onChange(setShowMail(????)}

but Where? on Checkbox? or inside styledtablecell. If inside styledtablecall how do I connect it with checkbox property?

this is where I' am confused

this is my render in App.js below-

import React, { Component, useState, useEffect } from "react";
        import axios from "axios";
        import { withStyles, makeStyles } from "@material-ui/core/styles";
        import Table from "@material-ui/core/Table";
        import TableBody from "@material-ui/core/TableBody";
        import TableCell from "@material-ui/core/TableCell";
        import TableContainer from "@material-ui/core/TableContainer";
        import TableHead from "@material-ui/core/TableHead";
        import TableRow from "@material-ui/core/TableRow";
        import Paper from "@material-ui/core/Paper";
        import Avatar from "@material-ui/core/Avatar";
        import Checkbox from "@material-ui/core/Checkbox";
        
        const StyledTableCell = withStyles((theme) => ({
          head: {
            backgroundColor: theme.palette.common.black,
            color: theme.palette.common.white,
          },
          body: {
            fontSize: 14,
          },
        }))(TableCell);
        
        const StyledTableRow = withStyles((theme) => ({
          root: {
            "&:nth-of-type(odd)": {
              backgroundColor: theme.palette.action.hover,
            },
          },
        }))(TableRow);
        
        const useStyles = makeStyles({
          table: {
            minWidth: 700,
          },
        });
        
        const App = () => {
          const classes = useStyles();
          const [users, setUsers] = useState([]);
          const [search, setSearch] = useState("");
          
        
          const getUserData = async () => {
            try {
              const data = await axios.get(
                //my json file structure. not attaching link due to privacy. 1000 users// users=[
    {
    "id":1,
    "first_name":"Suzie",
    "last_name":"something",
    "email":"jkshr.r@gmail.com",
    "gender":"Female",
    "Avatar":"https://..."
    
    },
]
    
              );
              console.log(data.data);
        
              setUsers(data.data);
            } catch (e) {
              console.log(e);
            }
          };
          useEffect(() => {
            getUserData();
          }, []);
        
        
            return (
                <div className="App">
                  <input
                    type="text"
                    placeholder="search here..."
                    onChange={(e) => {
                      setSearch(e.target.value);
                    }}
                  />
                  <TableContainer component={Paper} justify="center">
                    <Table className={classes.table} aria-label="customized table">
                      <TableHead>
                        <TableRow>
                          
                        </TableRow>
                      </TableHead>
                      <TableBody>
                        {users
                          .sort(function (a, b) {
                            if (a.last_name < b.last_name) {
                              return -1;
                            }
                            if (a.last_name > b.last_name) {
                              return 1;
                            }
                            return 0;
                          })
                          .filter((user) => {
                            if (search == "") {
                              return user;
                            } else if (
                              user.first_name
                                .toLowerCase()
                                .includes(search.toLowerCase()) ||
                              user.last_name.toLowerCase().includes(search.toLowerCase())
                            ) {
                              return user;
                            }
                          })
                          .map((user) => {
                            return (
                              <StyledTableRow key={user.id}>
                                <StyledTableCell component="th" scope="row" align="left">
                                  <Avatar>{user.avatar}</Avatar>
                                </StyledTableCell>
                                <StyledTableCell >
                                  {user.first_name} {user.last_name}
                                     
                                </StyledTableCell>
                                <Checkbox/>
                                
                              </StyledTableRow>
                            );
                          })}
                      </TableBody>
                    </Table>
                  </TableContainer>
                </div>
              );
        };
        export default App;

Thanks for all of your tips.




How to increase the size of checkbox of react-bootstrap?

This is a Checkbox from React-bootstrap.

   <Form.Group
      controlId="aCheckbox"
      as={Row}
    >
      <Form.Label>
        A Checkbox
      </Form.Label>
      <Col >
        <Form.Check
          type="checkbox"
        />
      </Col>
    </Form.Group>

How do I change the size of this checkbox?




Material UI Autocomplete component issue working with check

I have a Material UI autocomplete component with a checkbox component. How can I get both of them working such that only when a user selects an option from the autocomplete, the checkbox should get checked. Here is the link to my component:

https://codesandbox.io/embed/material-demo-forked-of2cz?codemirror=1