Ajoute un compteur sur les champ de type textarea sur l'interface usager

This commit is contained in:
Kara Diaby 2023-04-03 16:21:01 +02:00
parent ea3199d0f3
commit f3f49941b6
12 changed files with 114 additions and 26 deletions

View file

@ -24,4 +24,29 @@ class Champs::TextareaChamp < Champs::TextChamp
def for_export
value.present? ? ActionView::Base.full_sanitizer.sanitize(value) : nil
end
def character_count(text)
return text&.bytesize
end
def analyze_character_count(characters, limit)
if characters
threshold_75 = limit * 0.75
if characters >= limit
return :warning
elsif characters >= threshold_75
return :info
end
end
end
def remaining_characters(characters, limit)
threshold_75 = limit * 0.75
limit - characters if characters >= threshold_75
end
def excess_characters(characters, limit)
characters - limit if characters > limit
end
end