-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMessageForm.js
More file actions
38 lines (27 loc) · 832 Bytes
/
MessageForm.js
File metadata and controls
38 lines (27 loc) · 832 Bytes
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
export default function MessageForm({$target, onSubmit}) {
const $form = document.createElement('form')
$target.appendChild($form)
this.render = () => {
$form.innerHTML = `
<div>
<button class="msg_form_btn"type="button">
<i class="far fa-envelope"></i>
</button><input class="msg_form_input" type="text">
</div>
<button class="msg_form_submit">Submit</button>
`
}
this.render()
$form.addEventListener('submit', (e) => {
e.preventDefault()
const input = $form.querySelector('.msg_form_input')
onSubmit(input.value)
input.value = ''
})
window.addEventListener('Enter', (e) => {
e.preventDefault()
const input = $form.querySelector('.msg_form_input')
onSubmit(input.value)
input.value = ''
})
}