From 724c241bed6d8949ff77738006a1ff57a980fce4 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Thu, 13 Oct 2022 22:29:04 +0200 Subject: [PATCH] Count character count downwards instead of up --- .../retrospring/controllers/character_count_controller.ts | 2 +- app/views/answerbox/_comments.haml | 1 + app/views/application/_questionbox.haml | 4 ++-- app/views/modal/_ask.haml | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/javascript/retrospring/controllers/character_count_controller.ts b/app/javascript/retrospring/controllers/character_count_controller.ts index 885c8984..cbd37a58 100644 --- a/app/javascript/retrospring/controllers/character_count_controller.ts +++ b/app/javascript/retrospring/controllers/character_count_controller.ts @@ -18,7 +18,7 @@ export default class extends Controller { } update(): void { - this.counterTarget.innerHTML = String(`${this.inputTarget.value.length} / ${this.maxValue}`); + this.counterTarget.innerHTML = String(`${this.maxValue - this.inputTarget.value.length}`); if (this.inputTarget.value.length > this.maxValue) { if (!this.inputTarget.classList.contains('is-invalid') && !this.actionTarget.disabled) { diff --git a/app/views/answerbox/_comments.haml b/app/views/answerbox/_comments.haml index 08f9bc44..5fecefd3 100644 --- a/app/views/answerbox/_comments.haml +++ b/app/views/answerbox/_comments.haml @@ -30,3 +30,4 @@ %span.text-muted.form-control-feedback.comment__character-count{ id: "ab-comment-charcount-#{a.id}", data: { "character-count-target": "counter" } } 0 / 160 .input-group-append %button.btn.btn-primary{ type: :button, name: "ab-comment-new-submit", data: { a_id: a.id, "character-count-target": "action" } }= t(".action") + %span.text-muted.form-control-feedback.comment__character-count{ id: "ab-comment-charcount-#{a.id}", data: { "character-count-target": "counter" } } 160 diff --git a/app/views/application/_questionbox.haml b/app/views/application/_questionbox.haml index 6984c2f7..fd9ceb36 100644 --- a/app/views/application/_questionbox.haml +++ b/app/views/application/_questionbox.haml @@ -18,7 +18,7 @@ - if user_signed_in? || user.privacy_allow_anonymous_questions? #question-box{ data: { controller: "character-count", "character-count-max-value": 512 }} %textarea.form-control{ name: "qb-question", placeholder: t(".placeholder"), data: { "character-count-target": "input" } } - .row{ style: "padding-top: 5px; padding-left: 5px; padding-right: 5px;" } + .row{ style: "padding-top: 5px;" } .col-6 - if user_signed_in? - if user.privacy_allow_anonymous_questions? @@ -30,7 +30,7 @@ %input{ name: "qb-anonymous", type: :hidden, value: false }/ .col-6 %p.pull-right - %span.text-muted{ data: { "character-count-target": "counter" } } 0 / 512 + %span.text-muted.mr-1{ data: { "character-count-target": "counter" } } 512 %input{ name: "qb-to", type: "hidden", value: user.id }/ %button.btn.btn-primary{ name: "qb-ask", type: :button, diff --git a/app/views/modal/_ask.haml b/app/views/modal/_ask.haml index 667c763c..2589ed7b 100644 --- a/app/views/modal/_ask.haml +++ b/app/views/modal/_ask.haml @@ -9,7 +9,7 @@ .modal-body .form-group.has-feedback %textarea.form-control{ name: "qb-all-question", placeholder: t(".placeholder"), data: { "character-count-target": "input" } } - %p.text-right.text-muted.form-control-feedback{ data: { "character-count-target": "counter" } } 0 / 512 + %p.text-right.text-muted.form-control-feedback{ data: { "character-count-target": "counter" } } 512 .modal-footer %button.btn.btn-default{ type: :button, data: { dismiss: :modal } }= t("voc.cancel") %button.btn.btn-primary{ name: "qb-all-ask", type: :button, data: { "character-count-target": "action", loading_text: t(".loading") } }= t(".action")