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, jira product discovery, product operations, product ops, linkedin live, atlassian events, cross-functional collaboration, product management, engineering collaboration, design collaboration, atlassian learning, agile teams, product strategy

Product Ops Unpacked: 4️⃣ tips every product pro needs to know ✍️

Join PM Evangelist, Axel Sooriah, & Product Ops. Consultant & Advisor, Jenny Wanger, as they unpack the role of product ops and discuss key takeaways in Atlassian’s ‘The Product Ops Mission’ guide. They’ll answer your questions live on May 6 at 9:00am PT.

Register here ⬇️
AUG Leaders

Atlassian Community Events