From 6d473a83cc791daaaf8ecadb06315be8594e2990 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Mon, 12 Dec 2022 01:25:48 +0900 Subject: Add the character counter next to the Post button (#152) --- activities/views/compose.py | 13 +++++++++++++ activities/views/timelines.py | 13 +++++++++++++ 2 files changed, 26 insertions(+) (limited to 'activities/views') diff --git a/activities/views/compose.py b/activities/views/compose.py index 3c2e3a8..08b54ab 100644 --- a/activities/views/compose.py +++ b/activities/views/compose.py @@ -30,6 +30,19 @@ class Compose(FormView): "autofocus": "autofocus", "maxlength": Config.lazy_system_value("post_length"), "placeholder": "What's on your mind?", + "_": f""" + on load or input + set characters to my.value.trim().length + put { Config.system.post_length } - characters into #character-counter + + if characters > { Config.system.post_length } then + set #character-counter's style.color to 'var(--color-text-error)' + add [@disabled=] to #post-button + else + set #character-counter's style.color to '' + remove @disabled from #post-button + end + """, }, ) ) diff --git a/activities/views/timelines.py b/activities/views/timelines.py index b7a67c6..bcc6e7f 100644 --- a/activities/views/timelines.py +++ b/activities/views/timelines.py @@ -20,6 +20,19 @@ class Home(FormView): widget=forms.Textarea( attrs={ "placeholder": "What's on your mind?", + "_": f""" + on load or input + set characters to my.value.trim().length + put { Config.system.post_length } - characters into #character-counter + + if characters > { Config.system.post_length } then + set #character-counter's style.color to 'var(--color-text-error)' + add [@disabled=] to #post-button + else + set #character-counter's style.color to '' + remove @disabled from #post-button + end + """, }, ) ) -- cgit v1.2.3