Skip to content

Commit

Permalink
Merge pull request #3003 from bitzesty/textarea
Browse files Browse the repository at this point in the history
Ensure all non-breaking spaces and any other types of whitespace are replaced with regular spaces before performing .split on textarea wordcount
  • Loading branch information
DaniBitZesty authored Jul 16, 2024
2 parents 55f8649 + 2daf1fa commit a6d9bbb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/assets/javascripts/frontend/form-validation.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ window.FormValidation =
validateWordLimit: (question) ->
textarea = question.find("textarea")
wordLimit = textarea.attr("data-word-max")
normalizedContent = textarea.val().replace(/ /g, ' ').replace(/\n/g, ' ');
textareaValue = textarea.val() || '';
normalizedContent = textareaValue.replace(/( |\n|\s)+/g, ' ').trim();
wordCount = normalizedContent.split(" ").length
if wordCount > wordLimit
@logThis(question, "validateWordLimit", "Word limit exceeded")
Expand Down

0 comments on commit a6d9bbb

Please sign in to comment.