Skip to content

Commit 20764a3

Browse files
committed
[カスタムフィールドを連動させる] サンプル作成
1 parent b29b9eb commit 20764a3

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ If this project serves you well, please support this project as a [sponsor](http
1414
### Issue / チケット
1515

1616
* [Set the default value by tracker / トラッカーに応じてデフォルト値を設定](./examples/0003.set_default_value_by_tracker/example.md)
17+
* [Link custom fields (refining the children according to the parent value) / カスタムフィールドを連動させる(親の値に応じて、子を絞り込む)](./examples/0007.link_custom_fields/example.md)
1718

1819
### Issues list / チケット一覧
1920

@@ -28,7 +29,6 @@ If this project serves you well, please support this project as a [sponsor](http
2829

2930
### Old
3031

31-
* [カスタムフィールドを連動させる(親の値に応じて、子を絞り込む)](./old-examples/link_custom_field.js)
3232
* [コンテキストメニューを選択しやすくする](./old-examples/adjust_context_submenu.css)
3333
* [チケット一覧のコンテキストメニューでステータス変更を無効に](./old-examples/handling_issue_list_context_menu.js)
3434
* [チケットのステータスに応じて、カスタムフィールドの表示/非表示を切り替える](./old-examples/change_custom_field_visibility_when_change_status.js)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Link custom fields
2+
3+
Narrows down the choices of the child custom fields according to the value of the parent custom field.
4+
親のカスタムフィールドの値に応じて、子のカスタムフィールドの選択肢を絞ります。
5+
6+
## Setting
7+
8+
### Path Pattern
9+
10+
None
11+
12+
### Insert Position
13+
14+
Bottom of issue form
15+
<!--
16+
Head of all pages
17+
Bottom of issue form
18+
Bottom of issue detail
19+
Bottom of all pages
20+
-->
21+
22+
### Code
23+
24+
JavaScript
25+
<!--
26+
JavaScript
27+
CSS
28+
HTML
29+
-->
30+
31+
```javascript
32+
$(function() {
33+
34+
// Note: Change the ID according to the custom field you want to target.
35+
const parentFieldId = 'issue_custom_field_values_1';
36+
const childFieldId = 'issue_custom_field_values_2';
37+
38+
const isTarget = function(child, parent) {
39+
if (child.val() === '') {
40+
// Unselect is always target
41+
return true;
42+
}
43+
44+
// forward match
45+
return child.text().indexOf(parent.text()) == 0;
46+
}
47+
48+
const narrowChildField = function() {
49+
50+
const parentSelected = $('#' + parentFieldId + ' > option:selected');
51+
52+
$('#' + childFieldId + ' > option').each(function() {
53+
54+
const child = $(this);
55+
56+
// Narrow down by match.
57+
// (In IE, option is not hidden by "display:none", so "disabled" it to make it unselectable.)
58+
if (isTarget(child, parentSelected)) {
59+
child.show();
60+
child.prop('disabled', false);
61+
} else {
62+
child.hide();
63+
this.selected = false;
64+
child.prop('disabled', true);
65+
}
66+
});
67+
}
68+
69+
$('#' + parentFieldId).on('change', narrowChildField);
70+
71+
narrowChildField();
72+
});
73+
```
74+
75+
## Result
76+
77+
![result](./result.gif)
170 KB
Loading

0 commit comments

Comments
 (0)