-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.js
73 lines (52 loc) · 2.34 KB
/
form.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
console.clear();
// counter questionfield answerfield
const questionField = document.querySelector('[data-js="question-textfield"]');
const answerField = document.querySelector('[data-js="answer-textfield"]');
const charcount = document.querySelector('[data-js="question-charcount"]');
const charcount2 = document.querySelector('[data-js="answer-charcount"]');
function handleTextFieldInput(event, charcount) {
charcount.textContent =
event.target.getAttribute("maxlength") - event.target.value.length;
}
questionField.addEventListener("input", (event) => {
handleTextFieldInput(event, charcount);
});
answerField.addEventListener("input", (event) => {
handleTextFieldInput(event, charcount2);
});
// functionality for creating new cards
const form = document.querySelector('[data-js="form"]');
const cardList = document.querySelector('[data-js="cardlist"]');
form.addEventListener("submit", (event) => {
event.preventDefault();
// console.log("form submitted", event.target.elements.question1.value);
// console.log("form submitted", event.target.elements.answer1.value);
// console.log("form submitted", event.target.elements.hashtag1.value);
const listItem = document.createElement("li");
listItem.classList.add("card-list__item");
const questionCard = document.createElement("article");
questionCard.classList.add("card");
const questionText = document.createElement("h2");
questionText.classList.add("card__question");
questionText.textContent = event.target.elements.question1.value;
questionCard.append(questionText);
const answerText = document.createElement("p");
answerText.classList.add("card__answer");
answerText.textContent = event.target.elements.answer1.value;
console.log(event.target.elements.answer1.value);
questionCard.append(answerText);
const hashtagText = document.createElement("p");
hashtagText.classList.add("card__hashtag");
hashtagText.textContent = event.target.elements.hashtag1.value;
questionCard.append(hashtagText);
// questionCard.append(form);
listItem.append(questionCard);
cardList.append(listItem);
// if (event.target.elements.question1.value === "") {
// }
// if (event.target.elements.answer1.value === "") {
// }
// if (event.target.elements.hashtag1.value === "") {
// }
// console.log("form submitted", event.target.elements);
});