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

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

AJS.$('label[for=customfield_11329]').css({backgroundColor:'#red'});

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() {
    AJS.$(document).ready(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 http://stackoverflow.com/questions/3764821/best-way-to-restrict-a-text-field-to-numbers-only

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

0 votes

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.

AJS.$('#customfield_id').attr('maxlength','7')

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,011 views 12 18
Join discussion

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