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()
}