From 8b36c58864cf66e0d8e9b523ee63ea030e1138da Mon Sep 17 00:00:00 2001 From: Louis Kirkham Date: Mon, 9 Sep 2024 17:53:59 +0100 Subject: [PATCH] fix: Refactor word limit error message in QaeFormBuilder and TextareaQuestion Signed-off-by: Louis Kirkham --- forms/qae_form_builder/question.rb | 2 +- forms/qae_form_builder/textarea_question.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/forms/qae_form_builder/question.rb b/forms/qae_form_builder/question.rb index 39d748719..0a92bb2aa 100644 --- a/forms/qae_form_builder/question.rb +++ b/forms/qae_form_builder/question.rb @@ -48,7 +48,7 @@ def skip_base_validation? def limit_with_buffer(limit) if limit > 15 - (limit + limit * 0.1).to_i + 1 + (limit + limit * 0.1).to_i else limit end diff --git a/forms/qae_form_builder/textarea_question.rb b/forms/qae_form_builder/textarea_question.rb index 30c57e766..f04397747 100644 --- a/forms/qae_form_builder/textarea_question.rb +++ b/forms/qae_form_builder/textarea_question.rb @@ -9,12 +9,12 @@ def errors limit = question.delegate_obj.words_max - if limit && limit_with_buffer(limit) && length && length > (limit_with_buffer(limit) - 1) + if limit && limit_with_buffer(limit) && length && length > (limit_with_buffer(limit)) result[question.hash_key] ||= "" error = if limit_with_buffer(limit) > 15 - " Question #{question.ref} has a word limit of #{limit}. Your answer has to be #{limit_with_buffer(limit) - 1} words or less (as we allow 10% leeway)." + " Question #{question.ref} has a word limit of #{limit}. Your answer has to be #{limit_with_buffer(limit)} words or less (as we allow 10% leeway)." else - " Question #{question.ref} has a word limit of #{limit}. Your answer has to be #{limit_with_buffer(limit) - 1} word or less." + " Question #{question.ref} has a word limit of #{limit}. Your answer has to be #{limit_with_buffer(limit)} words or less." end result[question.hash_key] << error end