How to limit length of text field using javascript (while changing value of it on issue view screen)?

Paulina Wegrzyn December 1, 2015

Hello,

I have such problem - I need to have text field which can be only 8 characters long (it cannot be mandatory and need to be editable).

I added to "create" transition a scripted validator which checks if this field is 8 signs long, but the problem appeared here - during issue creation sometimes user do not know what she/he should put there, so this field cannot be mandatory during issue creation - it needs to be editable -> so I changed my validator to check if field is empty, if not empty if it has 8 characters (this is working perfectly good).

So this field needs to be editable -> I found such javascript (added it to field description):

<script type="text/javascript">
document.getElementById("customfield_16604").maxLength=8;
});
</script>

where: customfield_16604 is my field id

It works good while using edit screen of issue (screen below):

2.JPG

But if this field is added to edit screen it also can be edited form view of issue and here javascript does not work at all (field could have more than 8 signs and can be saved - screen below).

1.JPG

Do you have any idea what should I do to resolve it?

 

Thanks in advance,

Paulina

3 answers

0 votes
Maree Milne September 3, 2017

Did anyone find a resolution for this? We're having the same problem :(

0 votes
Andreas Meier April 30, 2017

Hi

I actually have the same problem:

  • JavaScript in Definition-Field works fine with <Edit Issue>
  • with Scriptrunner or Workflow Toolbox I can check conditions on state-transitions but

nothing works while editing a field on view screen (inline editing)

Is this problem solved?

 

0 votes
GabrielleJ
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 3, 2015

I'm not sure what Javascript/jQuery JIRA is using for the in-line editing of the custom fields. But my best guess i you will have to put your codes in the same location or put a "listener" on the custom field description to listener for any "key" changes 

Suggest an answer

Log in or Sign up to answer