From 57f8a64cf4d18b6f080ab68adadab7ada2be09ec Mon Sep 17 00:00:00 2001 From: kamos1 Date: Fri, 6 Oct 2017 12:24:58 -0600 Subject: [PATCH 1/3] fix issue 1037 --- client/talk-plugin-commentbox/CommentForm.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client/talk-plugin-commentbox/CommentForm.js b/client/talk-plugin-commentbox/CommentForm.js index f4bbbd139..347051a42 100644 --- a/client/talk-plugin-commentbox/CommentForm.js +++ b/client/talk-plugin-commentbox/CommentForm.js @@ -82,11 +82,16 @@ export class CommentForm extends React.Component { } } + removeNewLine = (string) => { + return string.replace(/\n/g, ''); + } + render() { const {maxCharCount, submitEnabled, cancelButtonClassName, submitButtonClassName, charCountEnable, body, loadingState} = this.props; - const length = body.length; - const isRespectingMaxCount = (length) => charCountEnable && maxCharCount && length > maxCharCount; + const cleanedBody = this.removeNewLine(body); + const length = cleanedBody.length; + const isRespectingMaxCount = (length) => charCountEnable && maxCharCount && length > maxCharCount; const disableSubmitButton = !length || isRespectingMaxCount(length) || !submitEnabled({body}) || loadingState === 'loading'; const disableCancelButton = loadingState === 'loading'; const disableTextArea = loadingState === 'loading'; From 8ab31d70093bca77739b57cba7e89b859efbf3f1 Mon Sep 17 00:00:00 2001 From: kamos1 Date: Fri, 6 Oct 2017 13:19:37 -0600 Subject: [PATCH 2/3] add trim to prevent empty spaces, tabs and other whitespace characters --- client/talk-plugin-commentbox/CommentForm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/talk-plugin-commentbox/CommentForm.js b/client/talk-plugin-commentbox/CommentForm.js index 347051a42..5093e3f1c 100644 --- a/client/talk-plugin-commentbox/CommentForm.js +++ b/client/talk-plugin-commentbox/CommentForm.js @@ -90,7 +90,7 @@ export class CommentForm extends React.Component { const {maxCharCount, submitEnabled, cancelButtonClassName, submitButtonClassName, charCountEnable, body, loadingState} = this.props; const cleanedBody = this.removeNewLine(body); - const length = cleanedBody.length; + const length = cleanedBody.trim().length; const isRespectingMaxCount = (length) => charCountEnable && maxCharCount && length > maxCharCount; const disableSubmitButton = !length || isRespectingMaxCount(length) || !submitEnabled({body}) || loadingState === 'loading'; const disableCancelButton = loadingState === 'loading'; From e95e0381c2157e96d6b40d683c93b7371e9970d0 Mon Sep 17 00:00:00 2001 From: kamos1 Date: Fri, 6 Oct 2017 13:25:32 -0600 Subject: [PATCH 3/3] remove removeNewLine and add .trim to length variable --- client/talk-plugin-commentbox/CommentForm.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/client/talk-plugin-commentbox/CommentForm.js b/client/talk-plugin-commentbox/CommentForm.js index 5093e3f1c..55d248994 100644 --- a/client/talk-plugin-commentbox/CommentForm.js +++ b/client/talk-plugin-commentbox/CommentForm.js @@ -82,15 +82,10 @@ export class CommentForm extends React.Component { } } - removeNewLine = (string) => { - return string.replace(/\n/g, ''); - } - render() { const {maxCharCount, submitEnabled, cancelButtonClassName, submitButtonClassName, charCountEnable, body, loadingState} = this.props; - const cleanedBody = this.removeNewLine(body); - const length = cleanedBody.trim().length; + const length = body.trim().length; const isRespectingMaxCount = (length) => charCountEnable && maxCharCount && length > maxCharCount; const disableSubmitButton = !length || isRespectingMaxCount(length) || !submitEnabled({body}) || loadingState === 'loading'; const disableCancelButton = loadingState === 'loading';