reset questionbox character counts after successful submit

This commit is contained in:
Andreas Nedbal 2022-10-31 21:23:22 +01:00
parent 15d05f1699
commit bef1c23a66
2 changed files with 11 additions and 3 deletions

View File

@ -22,6 +22,10 @@ export function questionboxAllHandler(event: Event): void {
if (data.success) {
document.querySelector<HTMLInputElement>('textarea[name=qb-all-question]').value = '';
window['$']('#modal-ask-followers').modal('hide');
// FIXME: also solve this using a Stimulus controller
const characterCount = document.querySelector<HTMLElement>('#modal-ask-followers [data-character-count-max-value]').dataset.characterCountMaxValue;
document.querySelector<HTMLElement>('#modal-ask-followers [data-character-count-target="counter"]').innerHTML = characterCount;
}
showNotification(data.message, data.success);

View File

@ -19,7 +19,7 @@ export function questionboxUserHandler(event: Event): void {
body: {
rcpt: document.querySelector<HTMLInputElement>('input[name=qb-to]').value,
question: document.querySelector<HTMLInputElement>('textarea[name=qb-question]').value,
anonymousQuestion: String(anonymousQuestion)
anonymousQuestion: String(anonymousQuestion)
},
contentType: 'application/json'
})
@ -29,6 +29,10 @@ export function questionboxUserHandler(event: Event): void {
if (data.success) {
document.querySelector<HTMLInputElement>('textarea[name=qb-question]').value = '';
// FIXME: also solve this using a Stimulus controller
const characterCount = document.querySelector<HTMLElement>('#question-box[data-character-count-max-value]').dataset.characterCountMaxValue;
document.querySelector<HTMLElement>('#question-box [data-character-count-target="counter"]').innerHTML = characterCount;
if (promote) {
const questionbox = document.querySelector('#question-box');
questionbox.classList.toggle('d-none');
@ -37,7 +41,7 @@ export function questionboxUserHandler(event: Event): void {
promote.classList.toggle('d-none');
}
}
showNotification(data.message, data.success);
})
.catch(err => {
@ -62,4 +66,4 @@ export function questionboxUserInputHandler(event: KeyboardEvent): void {
if (event.keyCode == 13 && (event.ctrlKey || event.metaKey)) {
document.querySelector<HTMLButtonElement>(`button[name=qb-ask]`).click();
}
}
}