Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create behaviour to count characters enterd in a Text field on each keypress Event ?

Sushmitha
Contributor
January 8, 2024

I have created a ScriptRunner behavior on a multiline text field to ensure that users enter at least 50 characters for the field before updating. If there are less than 50 characters entered, an error message is displayed along with the number of remaining characters left to complete 50 characters.

The behavior script is as below and it is working and number of remaining character is updating only when I move my cursor out of the field. But I want to update the remaining characters as soon as I enter the characters (on each keypress Event).

Is it possible to display updated number of characters on each keypress Event using behaviour ? 

If not, could you please tell me any other way that I can achieve this ?

 

final MIN_LENGTH = 50
def textField = getFieldByName("MultiLine Text Field")
def textFieldValue = textField.value as String
def textFieldLength = textFieldValue.trim().length()
if (textFieldLength < MIN_LENGTH) {
      textField.setError("Length of the \"Text Field\" should not be less than 50 chars ("+(MIN_LENGTH - textFieldLength)+" characters remaining)")
}
else {
      textField .clearError()
}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, likes for trees, atlassian community, social impact, tree planting campaign, community kudos, atlassian giving, environmental impact, sustainability, likes for good, atlassian social responsibility, community challenge

Make every click count—help us plant 50,000 trees! 🌳

Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!

Help us plant more trees
AUG Leaders

Atlassian Community Events