-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
40 lines (32 loc) · 918 Bytes
/
main.js
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
const contactName = document.getElementById('name')
const number = document.getElementById('number')
const address = document.getElementById('address')
const button = document.getElementById('button')
const contactList = document.querySelector('.contacts')
const store = window.localStorage
button.addEventListener('click', (e) => {
e.preventDefault()
if(contactName.value === "" || number.value === "" || address.value === ""){
return (
Swal.fire({
title: 'Error',
text: 'Debes completar todos los campos',
icon: 'error',
confirmButtonText: 'Aceptar',
})
)
}
const contact = {
id: Date.now(),
name: contactName.value,
number: number.value,
address: address.value,
}
createContact(store, contact)
loadContacts(store, contactList)
// Reseteo de los campos del formulario
contactName.value = ''
number.value = ''
address.value = ''
})
loadContacts(store, contactList)