compose_validate: Fix buggy separated handling of empty compose box.

When I adjusted 4fbf91c135 to no longer
do a full re-validation on every character typed, that unmasked bugs
in how the compose_setup handler code and compose_validate split
responsibility for validating 0-length messages.

The user-facing result was the send button not enabling properly when
starting to type.

Fix this by moving the 0-length message validation into
compose_validate, where we already handle issues of too-long messages,
sharing the same basic logic for determining when to do a full
validate() call.

A benefit of this reworking is now all of the logic for handling the
`invalid` class is in one place in validate, rather than split with
the compose_setup module.
This commit is contained in:
Tim Abbott
2025-03-17 13:13:37 -07:00
parent 24ada051dd
commit a6c5ddf102
4 changed files with 30 additions and 11 deletions

View File

@@ -77,9 +77,7 @@ export function initialize() {
}
compose_validate.warn_if_topic_resolved(false);
const compose_text_length = compose_validate.check_overflow_text($("#send_message_form"));
if (compose_text_length !== 0 && $("textarea#compose-textarea").hasClass("invalid")) {
$("textarea#compose-textarea").toggleClass("invalid", false);
}
// Change compose close button tooltip as per condition.
// We save compose text in draft only if its length is > 2.
if (compose_text_length > 2) {