Skip to content

Commit

Permalink
Merge pull request #3001 from bitzesty/wordcount
Browse files Browse the repository at this point in the history
Fix JS validation for word count in textarea
  • Loading branch information
DaniBitZesty committed Jul 16, 2024
2 parents 3882a99 + 18708ce commit d73681b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/assets/javascripts/frontend/form-validation.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ window.FormValidation =
return question.find("input[type='checkbox']").filter(":checked").length

validateWordLimit: (question) ->
wordLimit = $(question.context).attr("data-word-max")
wordCount = $(question.context).val().split(" ").length
textarea = question.find("textarea")
wordLimit = textarea.attr("data-word-max")
normalizedContent = textarea.val().replace(/ /g, ' ').replace(/\n/g, ' ');
wordCount = normalizedContent.split(" ").length
if wordCount > wordLimit
@logThis(question, "validateWordLimit", "Word limit exceeded")
@addErrorMessage(question, "Exceeded #{wordLimit} word limit.")
Expand Down

0 comments on commit d73681b

Please sign in to comment.