-
Notifications
You must be signed in to change notification settings - Fork 0
/
addWindow.html
46 lines (39 loc) · 1.4 KB
/
addWindow.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Add Shopping List Item</title>
<!-- MaterializeCSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
</head>
<body>
<div class="container">
<form>
<div>
<label>Enter an Item</label>
<!-- As soon as window loads, cursor will be auto focussed on input -->
<input type="text" id="item" autofocus>
</div>
<button class="btn waves-effect waves-light" type="submit" name="action">
Add Item
</button>
</form>
</div>
<script>
// ipcRenderer => will pass item's value to MainWindow through main.js
const electron = require("electron");
const {ipcRenderer} = electron;
const form = document.querySelector("form");
// When form is submitted
form.addEventListener('submit', submitForm);
function submitForm(event){
// Whenever we submit a form, it's automatically gonna be submitted to a file
// To prevent this default behavior from happening
event.preventDefault();
const item = document.querySelector("#item").value;
if(item){
ipcRenderer.send('item:add', item);
}
}
</script>
</body>
</html>