From 8dbc58ffa13536f1d084fff49e97d4cb475890a5 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 10 Oct 2020 00:21:20 -0400 Subject: [PATCH] disable empty string submissions --- vocodes/src/modes/speak/Form.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/vocodes/src/modes/speak/Form.tsx b/vocodes/src/modes/speak/Form.tsx index ba0f1f225e..67e9ad2e4b 100644 --- a/vocodes/src/modes/speak/Form.tsx +++ b/vocodes/src/modes/speak/Form.tsx @@ -222,12 +222,25 @@ class Form extends React.Component { this.textarea?.focus(); } + nonSpaceCharacterCount() : number { + return this.props.currentText.trim().length; + } + + remainingCharacterCount() : number { + return this.props.textCharacterLimit - this.props.currentText.length; + } + public render() { - let remainingCharacters = this.props.textCharacterLimit - this.props.currentText.length; + const nonWhitespaceCharacters = this.nonSpaceCharacterCount(); + const remainingCharacters = this.remainingCharacterCount(); let remainingCharactersButtonDisabled = false; let remainingCharactersClassName = ""; + if (nonWhitespaceCharacters === 0) { + remainingCharactersButtonDisabled= true; + } + if (remainingCharacters < 0) { remainingCharactersButtonDisabled= true; remainingCharactersClassName = "has-text-danger";