Setting a character limit on a text field (single line)

What mechanism can I use to set a maximum number of characters on a single line text field?

4 answers

OK, so after a lot of experimenting with JavaScript, I decided to embed the following into the Description field:

<script type="text/javascript">
function validate()
    {   
        if(document.getElementById("customfield_19600").value.length >33)
        {
            alert( "Invalid length, must be no more than 33 characters" );
            return false;
        }   
    }
document.getElementById("edit-issue-submit").addEventListener("click", validate);
</script>

Unfortunately, it never works. I can get the JS to work on test forms OUTSIDE of JIRA. But there's something I'm missing to get it working in the ticket "Edit" screen. Anyone have any suggestions?

I think that simple JS validation in the Description field is really helpful for people unfamiliar with Groovy (Script Runner), but I'm surprised how little I'm finding on it.

 

Hi Andy,

many thanks for sharing your script here! It actually helped me a lot.

Your script is working in my customers JIRA (still on version 6.2.5): If the field contains more than 33 char and I click the "update" button on the edit screen, the error message pop-up is shown.

I adapted the call of the EventListener for our purpose: Now the listener is listening for events on the field itself instead of the "update" button and throws the error immediately if the field contains more than 33 char (keypress event instead of click event).

Just changed the line:

document.getElementById("edit-issue-submit").addEventListener("click", validate);

to:

document.getElementById("customfield_19600").addEventListener("keypress", validate);

Regards, Sabrina

0 votes

Hack in some javascript, or change the template from 254 down (that will affect all short-text fields unless you start putting "if"s into the code).  Or, I think Behaviours in the Script runner can do it.

I guess it will have to be JavaScript; I don't have access to the templates, and don't want to do it for every field, anyway. I'll have a look at the ScriptRunner. Thanks!

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

274 views 0 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot