- JIRA 6.x Administration Cookbook
- Patrick Li
- 295字
- 2021-12-08 12:37:36
Using JavaScript with custom fields
Just as in the Adding help tips to custom fields recipe, we can also add JavaScript code in the custom field description as long as we wrap the code in the <script>
tags.
In this recipe, we will look at another way to remove the None option from select list custom fields.
Getting ready
This recipe uses the jQuery JavaScript library, which is bundled with JIRA. If you are not familiar with jQuery, you can find the documentation at http://jquery.com.
We will also need to use the custom field's ID in our script, so you will need to have that handy. You can find the ID by going to the custom fields page, clicking on the Edit link of the target field, and clicking the number at the end of the URL is the field's ID. For example, the following URL shows a custom field with the ID 10103
:
http://jira.localhost.com:8080/secure/admin/EditCustomField!default.jspa?id=10103
How to do it…
Proceed with the following steps to add JavaScript to custom field description:
- Log in to JIRA as a JIRA administrator.
- Navigate to Administration | Issues | Custom Fields.
- Click on the Edit link for the custom field.
- Enter the following JavaScript snippets into the Description text box and click on Update. You will need to substitute it in your custom field's ID.
<script> AJS.$('#customfield_10103 option[value="-1"]').remove(); </script>
The following screenshot shows that the Team custom field no longer has the None option:
How it works…
In our script, we use jQuery to select the Team custom field based on its element ID and remove the option with value -1 (which is the None option) with the selector #customfield_10103 option[value="-1"]
.
We use the Atlassian JavaScript (AJS ) namespace (AJS.$
), which is the recommended way to use jQuery in JIRA.
- Learning Microsoft Azure
- 基本有用的計量經(jīng)濟學(xué)
- 2016年度注冊會計師全國統(tǒng)一考試專用輔導(dǎo)教材(圖解版):審計
- 中國政府統(tǒng)計問題研究
- 中國國內(nèi)生產(chǎn)總值核算問題研究
- Microsoft SharePoint 2010 Developer’s Compendium:The Best of Packt for Extending SharePoint
- 效益實現(xiàn)管理實踐指南
- Force.com Tips and Tricks
- 中國重點經(jīng)濟領(lǐng)域統(tǒng)計分析
- 獨立審計質(zhì)量的激勵治理模式研究
- IBM Worklight Mobile Application Development Essentials
- Instant VMware Player for Virtualization
- 審計學(xué)學(xué)習(xí)指導(dǎo)與習(xí)題
- 經(jīng)濟指標簡史
- Learn Kubernetes Security