Customize the behaviour of a multicheckbox field

MarcoBaldo May 7, 2013

Hi everyone,

I'm quite new on the Jira developer environment, and still not sure about how to do some customization. I'm trying to write a script to customize the behaviour of a multicheckbox field.

I would like to realize a behaviour like the follow.

Option 1

Option 2

Option 3

Option 4

If "Option 1" is selected you can select just "Option 2". If "Option 3" is selected you cannot select "Option 1" and "Option 4" but you can select still "Option 2".

I was reading this question but I'm quite new of jira and I don't know javascript. I created the custom field I need with all the related options, I installed "behaviours plugin" and "script runner". I think that behaviour plugin is what I need. I wrote the following code to bind the Create issue

"AJS.$(document).bind('dialogContentReady', function(event, dialog) {

//do nothing

});"

but now how I can customize the options "checked/unchecked" or "enable/disabled" of my field?

2 answers

1 accepted

1 vote
Answer accepted
MarcoBaldo May 15, 2013

In the end I found a solution. I will do a short introduction for beginners like me about what I did.

It is possible to modify the behaviour of fields adding javascript in the "description" of a customfield.

To do scripts you use AJS (Atlassian Java Script) that uses the syntax of jQuery and some some special function (AJS Helper Functions).

https://developer.atlassian.com/display/AUI/AJS+helper+functions

A useful tool to try the scripting behaviour is the Sandbox, and also the "developer tool" of Google Chrome is a useful object.

This code in the end does what I need

<script type="text/javascript">

AJS.$("#customfield_10106-5").change(function() {

var all= AJS.$("#customfield_10106-5").is(':checked');

if(all===true){

AJS.$("#customfield_10106-1").prop("checked",false);

AJS.$("#customfield_10106-2").prop("checked",false);

AJS.$("#customfield_10106-3").prop("checked",false);

AJS.$("#customfield_10106-4").prop("checked",false);

AJS.$("#customfield_10106-6").prop("checked",false);

AJS.$("#customfield_10106-7").prop("checked",false);

AJS.$("#customfield_10106-1").attr("disabled", true);

AJS.$("#customfield_10106-2").attr("disabled", true);

AJS.$("#customfield_10106-3").attr("disabled", true);

AJS.$("#customfield_10106-4").attr("disabled", true);

AJS.$("#customfield_10106-6").attr("disabled", true);

AJS.$("#customfield_10106-7").attr("disabled", true);

}

else

{

AJS.$("#customfield_10106-1").attr("disabled", false);

AJS.$("#customfield_10106-2").attr("disabled", false);

AJS.$("#customfield_10106-3").attr("disabled", false);

AJS.$("#customfield_10106-4").attr("disabled", false);

AJS.$("#customfield_10106-6").attr("disabled", false);

AJS.$("#customfield_10106-7").attr("disabled", false);

}

});

</script>

0 votes
MarcoBaldo May 7, 2013

I got that another simply way to achive what I need is to use javascript code in the section "Description" of my custom field. But i cannot understant how to know if the options of a multi checkbox are checked or not. How can I get back the value of an option of my field?

Suggest an answer

Log in or Sign up to answer