简体   繁体   中英

How can I implement increase or decrease quantity till countInStock of my my e-commerce project with the below code?

I have made same thing using form Form.control . Here is the code and screenshot


    {product.countInStock > 0 && (
                    <ListGroupItem>
                      <Row>
                        <Col>Qty</Col>
                        <Form.Control
                          as="select"
                          value={qty}
                          onChange={(e) => setQty(e.target.value)}
                        >
                          {[...Array(product.countInStock).keys()].map((x) => (
                            <option key={x + 1} value={x + 1}>
                              {x + 1}
                            </option>
                          ))}
                        </Form.Control>
                      </Row>
                    </ListGroupItem>
                  )}

but I want the same thing in input tag format like this

                    <input
                      type="number"
                      value={qty}
                      onChange={(e) => setQty(e.target.valueAsNumber)}
                      min="0"
                      max={product.countInStock}
                    />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM