adding tag clears the input field
This commit is contained in:
parent
b15de6f803
commit
2c6adac225
|
@ -1,7 +1,7 @@
|
||||||
function add_tag(event) {
|
function add_tag(event) {
|
||||||
input = event.target.closest('.tag');
|
input_tag = event.target.closest('.tag');
|
||||||
post_id = input.closest('.post_container').id;
|
post_id = input_tag.closest('.post_container').id;
|
||||||
tag_name = input.children[0].value;
|
tag_name = input_tag.children[0].value;
|
||||||
fetch(url_prefix + '/add_tag', {
|
fetch(url_prefix + '/add_tag', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
@ -14,6 +14,7 @@ function add_tag(event) {
|
||||||
return response.json();
|
return response.json();
|
||||||
}).then(function(json) {
|
}).then(function(json) {
|
||||||
if (!json.ok) { throw new Error('Could not add tag.') }
|
if (!json.ok) { throw new Error('Could not add tag.') }
|
||||||
|
event.target.parentElement.firstElementChild.value = '';
|
||||||
let tag = document.createElement('span');
|
let tag = document.createElement('span');
|
||||||
tag.innerText = tag_name;
|
tag.innerText = tag_name;
|
||||||
tag.className = 'tag';
|
tag.className = 'tag';
|
||||||
|
@ -22,12 +23,11 @@ function add_tag(event) {
|
||||||
span.addEventListener('click', remove_tag);
|
span.addEventListener('click', remove_tag);
|
||||||
span.innerText = '-';
|
span.innerText = '-';
|
||||||
tag.appendChild(span);
|
tag.appendChild(span);
|
||||||
input.closest('.tags').insertBefore(tag, input);
|
input_tag.closest('.tags').insertBefore(tag, input_tag);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_tag(event) {
|
function remove_tag(event) {
|
||||||
console.log(event);
|
|
||||||
tag = event.target.closest('.tag');
|
tag = event.target.closest('.tag');
|
||||||
post_id = tag.closest('.post_container').id;
|
post_id = tag.closest('.post_container').id;
|
||||||
tag_name = tag.innerText.replace(/ .*/, '');
|
tag_name = tag.innerText.replace(/ .*/, '');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user