質問編集履歴
2
説明文の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,58 +1,49 @@
|
|
1
|
+
データ構造($test_list)
|
2
|
+
```ここに言語を入力
|
3
|
+
array(2) {
|
4
|
+
[0]=>
|
5
|
+
array(3) {
|
6
|
+
["test_name"]=>
|
7
|
+
string(15) "テスト太郎"
|
8
|
+
["test_d_name"]=>
|
9
|
+
string(6) "太郎"
|
1
|
-
|
10
|
+
["test_address"]=>
|
11
|
+
string(6) "東京"
|
12
|
+
}
|
13
|
+
[1]=>
|
14
|
+
array(3) {
|
15
|
+
["test_name"]=>
|
16
|
+
string(15) "テスト花子"
|
17
|
+
["test_d_name"]=>
|
18
|
+
string(6) "花子"
|
19
|
+
["test_address"]=>
|
20
|
+
string(6) "大阪"
|
21
|
+
}
|
22
|
+
}
|
2
|
-
```
|
23
|
+
```
|
3
|
-
|
24
|
+
■実現したい事
|
25
|
+
(1)「名前を追加」ボタンにて、ラベルを追加して、同じように「選択してください」ラベルから選んだ「$test_list[idx].test_name」から
|
4
|
-
|
26
|
+
同じ配列インデックスの「test_d_name」と「test_address」の値をテキストボックスに表示させたいです。
|
5
|
-
{
|
6
|
-
|
7
27
|
|
28
|
+
idの重複はjavascriptではNGなので「test.tpl」の「id="select_test_info"」を「id="select_test_info1"」として、
|
29
|
+
「名前を追加」ボタンを押して、ラベル追加した際2番目のidが「id="select_test_info2"」3番目のidが「id="select_test_info3"」
|
30
|
+
となっていくのでtplの下記部分をそれに対応したように、「document.getElementById('select_test_info2').addEventListener」
|
31
|
+
「document.getElementById('select_test_info3').addEventListener」となるようにしたいのですが、どのように
|
8
|
-
|
32
|
+
したら良いかわからなく悩んでいます。
|
9
|
-
// ↓
|
10
|
-
// ここではtest_name[0]の値が表示されます。
|
11
33
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
content += '{section name=idx loop=$test_list}';
|
22
|
-
content += '<option value="{$test_list[idx].test_name|escape:"html"}"{if $test_list[idx].test_name == $test_list} selected{/if} data-disp="{$test_list[idx].test_d_name}" data-address="{$test_list[idx].test_address}">{$test_list[idx].tes_name}</option>';
|
23
|
-
content += '{/section}';
|
24
|
-
content += '</select></td>';
|
25
|
-
|
26
|
-
content += '<td><input type="text" name="test_d_name['+next_idx+']" value="" placeholder="名" /></td>';
|
27
|
-
content += '<td><input type="text" name="test_address['+next_idx+']" value="" placeholder="住所" /></td>';
|
28
|
-
content += '<td><button type="button" id="btn_del_test'+next_idx+'" class="deleteTest ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-delete">削除</button></td>';
|
29
|
-
content += '</tr>';
|
30
|
-
$('#test_tbody').append(content);
|
31
|
-
//Table Tag 再構築
|
32
|
-
$('#test_tbody').trigger('create');
|
34
|
+
(2)ラベルを「選択してください」に戻すと、テキストボックス欄が「undefined」となってしまいます。
|
35
|
+
tplの下記部分に、
|
36
|
+
```ここに言語を入力
|
37
|
+
if ( option.indexOf("選択してください") != -1) {
|
38
|
+
document.querySelector('input[name^="test_d_name"]').value = option.dataset.disp;
|
39
|
+
}
|
40
|
+
```
|
41
|
+
と記載して、「選択してください」ラベルがない場合のみ表示させようとしているのですが、うまく
|
42
|
+
いかなく悩んでいます。
|
33
43
|
|
34
|
-
|
44
|
+
以上の2点をどのようにしたら良いかご教授いただきたくお願い致します。
|
35
|
-
});
|
36
|
-
```
|
37
45
|
●test.tpl
|
38
46
|
```html
|
39
|
-
{if count($test_list) > 0}
|
40
|
-
{assign var='i' value=0}
|
41
|
-
{section name=idx1 loop=$test_list}
|
42
|
-
test_name[{$i}] = '{$test_list[idx1].test_name}';
|
43
|
-
test_d_name[{$i}] = '{$test_list[idx1].test_d_name}';
|
44
|
-
{assign var='i' value=$i+1}
|
45
|
-
{/section}
|
46
|
-
{/if}
|
47
|
-
{*
|
48
|
-
↑
|
49
|
-
ここでの値は正常に表示されています。
|
50
|
-
test_name[0] = 'テスト太郎';
|
51
|
-
test_d_name[0] = '太郎';
|
52
|
-
test_name[1] = 'テスト花子';
|
53
|
-
test_d_name[1] = '花子';
|
54
|
-
*}
|
55
|
-
|
56
47
|
<script language="JavaScript" src="test.js?t={$smarty.now}"></script>
|
57
48
|
|
58
49
|
・
|
@@ -76,7 +67,7 @@
|
|
76
67
|
<tr>
|
77
68
|
<td><input type="radio" id="in_test_radio{$i}" name="test_radio[{$i}]"/></td>
|
78
69
|
<td>
|
79
|
-
<select name="test_info" id="
|
70
|
+
<select name="test_info" id="select_test_info1" data-native-menu="true">
|
80
71
|
<option value="">選択してください</option>
|
81
72
|
{section name=idx loop=$test_list}
|
82
73
|
<option value="{$test_list[idx].test_name|escape:"html"}"{if $test_list[idx].test_name == $test_list} selected{/if} data-disp="{$test_list[idx].test_d_name}" data-address="{$test_list[idx].test_address}">{$test_list[idx].test_name}</option>
|
@@ -98,25 +89,46 @@
|
|
98
89
|
・
|
99
90
|
</div>
|
100
91
|
<script type="text/javascript">
|
92
|
+
var next_idx = $('#test_tbody').children().length;
|
93
|
+
// console.log(next_idx);
|
101
94
|
document.getElementById('select_test_info').addEventListener('change', function(event) {
|
102
95
|
var option = this.options[this.selectedIndex];
|
103
|
-
console.log(option);
|
96
|
+
// console.log(option);
|
104
|
-
if ( option.indexOf("選択してください") != -1) {
|
97
|
+
// if ( option.indexOf("選択してください") != -1) {
|
105
98
|
document.querySelector('input[name^="test_d_name"]').value = option.dataset.disp;
|
106
|
-
}
|
99
|
+
// }
|
107
100
|
document.querySelector('input[name^="test_address"]').value = option.dataset.address;
|
108
101
|
}, false);
|
109
102
|
</script>
|
110
103
|
</body>
|
111
104
|
</html>
|
112
105
|
```
|
106
|
+
●test.js(「名前を追加」ボタンを押した際)
|
107
|
+
```js
|
108
|
+
//名前の行を追加する
|
109
|
+
$(document).on("click", ".addName", function()
|
110
|
+
{
|
111
|
+
var content = '';
|
112
|
+
var next_idx = $('#test_tbody').children().length;
|
113
|
+
next_idx++;
|
114
|
+
content += '<tr>';
|
115
|
+
content += '<td><input type="radio" id="in_test_radio{$i}" name="test_radio['+next_idx+']" value="'+next_idx+'" /></td>';
|
116
|
+
content += '<td><select name="test_info" id="select_test_info'+next_idx+'" data-native-menu="true">';
|
117
|
+
content += '</select></td>';
|
118
|
+
|
119
|
+
content += '<td><input type="text" name="test_d_name['+next_idx+']" value="" placeholder="名" /></td>';
|
120
|
+
content += '<td><input type="text" name="test_address['+next_idx+']" value="" placeholder="住所" /></td>';
|
121
|
+
content += '<td><button type="button" id="btn_del_test'+next_idx+'" class="deleteTest ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-delete">削除</button></td>';
|
122
|
+
content += '</tr>';
|
123
|
+
$('#test_tbody').append(content);
|
124
|
+
// selectの中身を足す
|
113
|
-
|
125
|
+
$('#select_test_info'+next_idx).append($('#select_test_info').children().clone(true));
|
114
|
-
|
126
|
+
//Table Tag 再構築
|
127
|
+
$('#test_tbody').trigger('create');
|
115
128
|
|
129
|
+
return false;
|
130
|
+
});
|
131
|
+
```
|
132
|
+
となっております。
|
116
|
-
|
133
|
+
ご教授いただきたくお願い申し上げます。
|
117
|
-
|
118
|
-
★「名前を追加」ボタンにて「test.js」にて、ラベルを追加したいのですが、追加された「選択してください」ラベルを操作すると、
|
119
|
-
「$test_list[idx].test_name」が表示され、リスト選択できない状態です。
|
120
|
-
|
121
|
-
|
122
|
-
|
134
|
+
宜しくお願いします。
|
1
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
//名前の行を追加する
|
4
4
|
$(document).on("click", ".addName", function()
|
5
5
|
{
|
6
|
-
|
6
|
+
|
7
7
|
|
8
8
|
console.log(test_name);
|
9
9
|
// ↓
|