aboutsummaryrefslogtreecommitdiff
path: root/src/components/Form/Form.js
blob: 3285548e2b5062a819fdd987e4bd5c225fc755fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, { useState } from "react";
import "./Form.css";


const BillingForm = (props) => {
  const [itemValue, setItemValue] = useState("");
  const [descValue, setDescValue] = useState("");

  const savedItems = props.savedItems;
  let savedItemNames = []
  for (let i = 0; i < savedItems.length; i++) {
    savedItemNames.push(savedItems[i].Model)
  }

  const filteredItems = savedItemNames.filter(
    (item) => {
      // case insensitive
      return item.toLowerCase().includes(itemValue.toLowerCase());
    }
  );
  
  return (
    <div>
      <form onSubmit={
        (event) => {
          event.preventDefault();
          console.log(itemValue, descValue);
        }
      }>
  
        <label>
          Item: <input type="text" value={itemValue} onChange={
            (event) => {
              setItemValue(event.target.value);
            }
          } />
        </label>
  
        <label>
          Description: <input type="text" value={descValue} onChange={
            (event) => {
              setDescValue(event.target.value);
            }
          } />
        </label>

        <input type="submit" value="add" />
      </form>

      <ul>
        {filteredItems.map(
          (i) => {
            return <li key={i}>{i}</li>
          }
        )}
      </ul>
    </div>
  )
}

export default BillingForm;