Remove the None option from a select list custom field in Jira server

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

The content on this page is a customisation. It is not supported by Atlassian Support. Please comment below with additional tips!

プラットフォームについて: Data Center のみ - この記事は、Data Center プラットフォームのアトラシアン製品にのみ適用されます。

この KB は Data Center バージョンの製品用に作成されています。Data Center 固有ではない機能の Data Center KB は、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。

*Fisheye および Crucible は除く

概要

There are some instances where the 'NONE' in every select list needs to be removed. This can be achieved by making the field required or optional. Once the field is set to "Required", please make sure to take the 'NONE' value out of the Custom Field configuration (both as an actual option if present and as the default value for the field) or the 'NONE' value will still be an option.

If this is not an option, it is possible to customize JIRA applications to allow this behavior. This can be achieved by following this guide.

(info) This guide is not kept up-to-date and velocity templates will change from version-to-version. The information provided is a guide only and may no longer be relevant in certain versions of JIRA applications.

回避策 1

This workaround will apply to all Select List Custom Fields in the instance (the edit-select.vm template is used by all Select List Custom Fields).

To remove the field, edit atlassian-jira/WEB-INF/classes/templates/plugins/fields/edit/edit-select.vm. Delete the lines:

...
  #if (!$fieldLayoutItem || $fieldLayoutItem.required == false
    <option value="-1">$i18n.getText("common.words.none")</option>
  #else
    <option value="">$i18n.getText("common.words.none")</option>
  #end
...

The following code should remain:

...
<select name="$customField.id" id="$customField.id">  #foreach ($option in $configs.options)
    <option value="$textutils.htmlEncode($option.value)"
  #if ($value && $value == $option.value)selected#end
    >$option.value</option>
  #end
</select>
...

Save the edited file and restart Jira.

回避策 2

If a more selective approach is required, it's possible to remove the 'NONE' value only for a specific Select List Custom Field, based on the field's ID.

First, find the Custom Field's ID using one of the methods described in How to find any custom field's IDs.

Then edit atlassian-jira/WEB-INF/classes/templates/plugins/fields/edit/edit-select.vm and locate the following code:

...
  #if (!$fieldLayoutItem || $fieldLayoutItem.required == false
    <option value="-1">$i18n.getText("common.words.none")</option>
  #else
    <option value="">$i18n.getText("common.words.none")</option>
  #end
...

Enclose the code above with an if statement as follows, replacing FIELDID with the numeric field ID obtained earlier:

...
  #if ($customField.id != "customfield_FIELDID")
    #if (!$fieldLayoutItem || $fieldLayoutItem.required == false
      <option value="-1">$i18n.getText("common.words.none")</option>
    #else
      <option value="">$i18n.getText("common.words.none")</option>
    #end
  #end
...

Save the edited file and restart Jira.


Make sure to back up the velocity file before changing it. Keep in mind the notes from Jira templates and JSPs.

Workaround for Select List (cascading) 

Similar to the customization steps suggested for edit-select.vm it would be possible to edit the edit-cascadingselect.vm with the code below to remove the 'NONE' option from the "Select List (Cascading)" custom field.


#disable_html_escaping()
#if (!$request || !$request.getAttribute("cascade"))
    $!request.setAttribute("cascade" , "true")
#end
#if ($value.getValuesForNullKey() && !$value.getValuesForNullKey().empty)
    #set ($selectedParent = $value.getValuesForNullKey().iterator().next())
#end
#if ($value.getValuesForKey('1') && !$value.getValuesForKey('1').empty)
    #set ($selectedChild = $value.getValuesForKey('1').iterator().next())
#end
$!{auiparams.put("controlHeaderClass", "aui-field-cascadingselect")}
$!{auiparams.put("controlHeaderRole", "group")}
#customControlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters $auiparams)
    <select class="select cascadingselect-parent" id="${customField.id}" name="${customField.id}">
        #if ($configs.options.rootOptions.size() == 0)
            <option value="">$i18n.getText("common.words.none")</option>
        #end
        #set ($hadSelectedParentOption = false)
        #foreach ($option in $configs.options.rootOptions)
            #set ($extraAttrs = "")
            #if ($selectedParent && $selectedParent == $option.optionId)
                #set ($hadSelectedParentOption = true)
                #set ($extraAttrs = ' selected="selected"')
            #end
            #if (!$option.disabled || ($selectedParent && $selectedParent == $option.optionId))
                <option class="option-group-$option.optionId" value="$option.optionId"$extraAttrs>$cfValueEncoder.encodeForHtml($option.value)</option>
            #end
        #end
        ## render parent option assigned to the issue (databaseParent) but not present in the relevant custom field context (configs.options.rootOptions)
        #if ($databaseParent && !$hadSelectedParentOption)
            <option class="option-group-$databaseParent.optionId" value="$databaseParent.optionId" selected="selected">$i18n.getText("customfield.not.available.in.scheme", $cfValueEncoder.encodeForHtml($databaseParent.value))</option>
        #end
    </select>
    <select class="select cascadingselect-child" id="${customField.id}:1" name="${customField.id}:1" aria-labelledby="${customField.id}">
        #set ($hadSelectedChildOption = false)
        #foreach ($parentOption in $configs.options.rootOptions)
            #if ($parentOption.childOptions.size() == 0)
                <option value="">$i18n.getText("common.words.none")</option>
         .   #end	
            #foreach ($childOption in $parentOption.childOptions)
                #set ($extraAttrs = "")
                #if ($selectedChild && $selectedChild == $childOption.optionId)
                    #set ($hadSelectedChildOption = true)
                    #set ($extraAttrs = ' selected="selected"')
                #end
                #if (!$childOption.disabled || ($selectedChild && $selectedChild == $childOption.optionId))
                    <option class="option-group-$parentOption.optionId" value="$childOption.optionId"$extraAttrs>$cfValueEncoder.encodeForHtml($childOption.value)</option>
                #end
            #end
        #end
        ## render child option assigned to the issue (databaseChild) but not present in the relevant custom field context
        #if ($databaseChild && !$hadSelectedChildOption)
            <option class="option-group-$databaseParent.optionId" value="$databaseChild.optionId" selected="selected">$i18n.getText("customfield.not.available.in.scheme", $cfValueEncoder.encodeForHtml($databaseChild.value))</option>
        #end
    </select>
#customControlFooter ($action $customField.id $fieldLayoutItem.fieldDescription $displayParameters $auiparams)
$!{auiparams.clear()}
Last modified on Mar 29, 2023

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.