Is it possible to limit the number of digits in a custom number field

1. I would like to keep the custom field limited to 1 digit (e.g. a number between 0 and 9) with no decimal point. is it possible?

2. currently the field is shown with a very long edit box. can I shorten also the edit box size to indicate that only a small value is expected?

7 answers

1 accepted

1 vote
Accepted answer

as you said if you are expecting decimal value 1 to 9 and field limit is 1 digit then create a select list and add 1 o 9 values as a options. so can able to select only those values.

i think this is what you are expecting!!!

i think using javascript you can achive!!

Thanks guys, but i was actually looking for something simpler, which is some way to set attributes for the existing field.

for example:

1. configure that this field has only one digit after the decimal point (e.g. nnn.x)

2. configure a valid range of numbers (min/max) for the input.

3. show a smaller edit box of 5 charachters istead of a full line.

So nothing of the above comes out of the box? or is there some simple way to get there?

Thanks a lot ! This is the right direction - already managed to change the edit box size.

Can you please indicate how can I change the style of the title of the field (i.g. thegetElementById("customfield_12345") returns the field itself, not its title element.

Hey, found it myself. This is a way to get the ID of the label used a the caption of a custom field/control:

function findLabelByControlName(ctr) {
   labels = document.getElementsByTagName('label');
   for( var i = 0; i < labels.length; i++ ) {
      //if (i<20) alert (labels[i].htmlFor);
      if (labels[i].htmlFor == ctr)
           return labels[i];
 }// end of Function ()

to change the style of the style of the title you can do it simple way,

for example to change color of label text, i used this


just change on css if you want to change some thing

You'll have to write a small plugin for that. It shouldn't be hard since all you have to do is extend the existing NumberCFType and add a validation and a custom view.

Thanks a lot ! This is the right direction - already managed to change the edit box size.

Can you please indicate how can I change the style of the title of the field (i.g. the getElementById("customfield_12345") returns the field itself, not its title element.

One approach to restrict a text field to specific characters or specific length would be using javascript. Something like

AJS.$(function() {
        var textInput = AJS.$("#textInputElement");
        textInput.onkeydown = textInput.onkeyup = textInput.onblur = function() {
             textInput.value = textInput.value.replace(/[^0-9]+/, "");

example above removes everything from text input element that is not matching numbers 0-9 as you type.

refer to for further info

Note: This should work everywhere but in Dialogs. Because elements that are rendered in dialogs are not present when DOM is build up. They are added to the DOM when the Dialog appears. Hence textInput in example above would not be found on document.ready event and therefore the script not applied.

You can however catch the JIRA.Events.NEW_CONTENT_ADDED event. It is fired when something is added to the DOM, such as a new Dialog. So if you want javascript to be applied to elements inside Dialogs. You would bind your function to new content added event. Example

AJS.$(function() {
    // execute on popup
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context, reason) {
    	 var $context = AJS.$(context);	
    	 // dialog appeared 
    	 if(reason == JIRA.CONTENT_ADDED_REASON.dialogReady){
    		 // get elements. notice: context gives you an array of elements. if you are sure that there is only one - use $context.find(#inputElement")[0];
    		 var inputElements = $context.find("#inputElement");
                 // ... from here do what you want with inputElement

You can do a simple validator with script runner, asserting the input matches a regex.

You can set the maxlength attribute to the existing customfield by using javascript.


cant you just add maxlength attribute to vm template?

<input .... maxlength="7" />

Thanks for all the helpul answers above.

In addition to the above, here is the way I applied a simple validation, applied once the "update" button of the form is clicked (i.e. to submit):

btn = document.getElementById('edit-issue-submit');
   btn.onclick = function ()
     if (condition) 
          alert ("Value must be a number between 0 and 9");

if the button is note "Update" but "Create", the the button name should be 'create-issue-submit' in the code above

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,725 views 17 21
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