Skip to content

Commit c60baad

Browse files
committed
update search
1 parent c19db20 commit c60baad

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

assignment-1/index.html

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,21 @@ <h3>
113113
<div class="item_form_add">
114114
<label for="topic">Topic</label>
115115
<select required id=" topic" name="topic">
116-
<option>
117-
Programing
118-
</option>
119-
<option>
120-
Database
121-
</option>
122-
<option>
123-
DevOps
124-
</option>
116+
<div>
117+
<option>
118+
Programing
119+
</option>
120+
</div>
121+
<div>
122+
<option>
123+
Database
124+
</option>
125+
</div>
126+
<div>
127+
<option>
128+
DevOps
129+
</option>
130+
</div>
125131
</select>
126132
</div>
127133

assignment-1/script.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,28 @@ function App() {
8989
node.innerHTML = html
9090
return node
9191
}
92+
function handleCheckInputSearch() {
93+
if (inputSearch.value.trim() !== '') {
94+
const dataFilter = dataBooks.filter(item => item.name.toLowerCase().includes(inputSearch.value.toLowerCase()))
95+
handleRenderDataTable(dataFilter)
96+
} else {
97+
handleRenderDataTable(dataBooks)
98+
}
99+
}
92100
function handleDelBook(idBook, dataBook) {
93101
const newData = dataBooks.filter((data, index) => data.name !== dataBook.name)
94102
dataBooks = [...newData]
95-
handleRenderDataTable(newData)
103+
handleCheckInputSearch()
96104
handleCloseModalDelBook()
97105
}
106+
98107
function handleAddBook(e) {
99108
e.preventDefault()
100109
const data = Object.fromEntries(new FormData(e.target).entries());
101110
if (checkIsHaveData(data)) {
102111
dataBooks.push(data)
103112
document.querySelectorAll('input:not(.input_search)').forEach(item => item.value = '') // reset value input
104-
if (inputSearch.value.trim() === '') {
105-
handleRenderDataTable(dataBooks)
106-
} else {
107-
const dataFilter = dataBooks.filter(item => item.name.toLowerCase().includes(inputSearch.value))
108-
handleRenderDataTable(dataFilter)
109-
110-
}
113+
handleCheckInputSearch()
111114
handleToggleModalAddBook()
112115
} else {
113116
alert('Vui Long Nhap Day Du')
@@ -134,7 +137,7 @@ function App() {
134137
}
135138

136139
function handleRenderDataTable(data) {
137-
localStorage.setItem('databook', JSON.stringify(data))
140+
localStorage.setItem('databook', JSON.stringify(dataBooks))
138141
let dataTable = data?.map((data, index) => {
139142
return `
140143
<tr>
@@ -163,7 +166,6 @@ function App() {
163166
)
164167
})
165168

166-
console.log(btnRemoves)
167169
}
168170

169171

assignment-1/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ button {
2626
}
2727

2828
input,
29+
option,
2930
select {
3031
padding: 15px 30px;
3132
border-radius: 4px;
3233
outline: none;
3334
border: 2px solid #606060;
3435
margin: 5px 0;
3536
width: 100%;
37+
font-size: 16px;
38+
font-weight: 600;
3639
}
3740

41+
select {}
42+
3843
::placeholder {
3944
font-size: 16px;
4045
font-weight: 600;

0 commit comments

Comments
 (0)