質問編集履歴
3
viewの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -204,6 +204,20 @@
|
|
204
204
|
|
205
205
|
```
|
206
206
|
|
207
|
+
```view
|
208
|
+
|
209
|
+
# 削除へのリクエストに対する処理
|
210
|
+
|
211
|
+
def delete(request, id):
|
212
|
+
|
213
|
+
employee = get_object_or_404(User, pk=id)
|
214
|
+
|
215
|
+
employee.delete()
|
216
|
+
|
217
|
+
return redirect('employee:show')
|
218
|
+
|
219
|
+
```
|
220
|
+
|
207
221
|
|
208
222
|
|
209
223
|
### 試したこと
|
2
onsubmit属性の活用
test
CHANGED
File without changes
|
test
CHANGED
@@ -210,41 +210,21 @@
|
|
210
210
|
|
211
211
|
|
212
212
|
|
213
|
-
```
|
213
|
+
```
|
214
|
-
|
214
|
+
|
215
|
-
|
215
|
+
<!-- 更新と削除のボタン表示 -->
|
216
216
|
|
217
217
|
<td class="edit">
|
218
218
|
|
219
219
|
<button><a href="{% url 'employee:update' id=value.id %}"><img src="{% static "employee/update-btn.png" %}"></a></button>
|
220
220
|
|
221
|
-
<
|
221
|
+
<form name="delete_form" id="delete_form" onsubmit="return confirm();" method="post" action="{% url 'employee:delete' id=value.id %}"></form>
|
222
|
-
|
223
|
-
|
222
|
+
|
224
|
-
|
225
|
-
|
223
|
+
{% csrf_token %}
|
226
|
-
|
227
|
-
|
224
|
+
|
228
|
-
|
229
|
-
<h3>登録者情報の削除確認</h3>
|
230
|
-
|
231
|
-
<div>
|
232
|
-
|
233
|
-
この行を削除しますか?
|
234
|
-
|
235
|
-
</div>
|
236
|
-
|
237
|
-
<footer>
|
238
|
-
|
239
|
-
<button id='cancel_button'>いいえ</button>
|
240
|
-
|
241
|
-
|
225
|
+
<button id='del_btn' class='del_btn' type="submit"><img src="{% static "employee/delete-btn.png" %}"></button>
|
242
|
-
|
243
|
-
|
226
|
+
|
244
|
-
|
245
|
-
</dialog>
|
246
|
-
|
247
|
-
</form>
|
227
|
+
</form>
|
248
228
|
|
249
229
|
</td>
|
250
230
|
|
@@ -256,47 +236,61 @@
|
|
256
236
|
|
257
237
|
</table>
|
258
238
|
|
239
|
+
|
240
|
+
|
259
|
-
|
241
|
+
<div id="dl2" style="display:none;">
|
242
|
+
|
260
|
-
|
243
|
+
<p>この行を削除しますか?</p>
|
244
|
+
|
261
|
-
<
|
245
|
+
</div>
|
262
|
-
|
263
|
-
|
246
|
+
|
264
|
-
|
265
|
-
function clickDelete(id){
|
266
|
-
|
267
|
-
const dialog = document.getElementById("dialog");
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
247
|
+
<script type="text/javascript">
|
272
|
-
|
248
|
+
|
273
|
-
|
249
|
+
/* function confirm() {} */
|
274
|
-
|
275
|
-
}else{
|
276
|
-
|
277
|
-
dialog.style.display = "block";
|
278
|
-
|
279
|
-
}
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
document.getElementById("cancel_button").addEventListener('click',() =>{
|
284
|
-
|
285
|
-
return false;
|
286
|
-
|
287
|
-
dialog.style.display = "none";
|
288
|
-
|
289
|
-
})
|
290
|
-
|
291
|
-
}
|
292
250
|
|
293
251
|
|
294
252
|
|
253
|
+
$(function confirm() {
|
254
|
+
|
255
|
+
$(".del_btn").click(function() {
|
256
|
+
|
257
|
+
$("#dl2").dialog({
|
258
|
+
|
259
|
+
modal:true,
|
260
|
+
|
261
|
+
title:"登録者情報の削除確認",
|
262
|
+
|
263
|
+
buttons: {
|
264
|
+
|
265
|
+
"はい": function() {
|
266
|
+
|
267
|
+
$(this).dialog("close");
|
268
|
+
|
269
|
+
},
|
270
|
+
|
271
|
+
"いいえ": function() {
|
272
|
+
|
273
|
+
return false;
|
274
|
+
|
275
|
+
$(this).dialog("close");
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
});
|
282
|
+
|
283
|
+
});
|
284
|
+
|
285
|
+
});
|
286
|
+
|
295
287
|
</script>
|
296
288
|
|
297
289
|
```
|
298
290
|
|
291
|
+
formタグにonsubmit属性を追加
|
292
|
+
|
299
|
-
|
293
|
+
ダイアログで『いいえ』を選択するとsubmitをキャンセルさせる
|
300
294
|
|
301
295
|
### 補足情報(FW/ツールのバージョンなど)
|
302
296
|
|
1
jQueryを活用したことによるコード変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,6 +48,24 @@
|
|
48
48
|
|
49
49
|
```HTML
|
50
50
|
|
51
|
+
<!-- CSSの設定 -->
|
52
|
+
|
53
|
+
{% load static %}
|
54
|
+
|
55
|
+
<link rel="stylesheet" type="text/css" href="{% static 'employee/reset.css' %}">
|
56
|
+
|
57
|
+
<link rel="stylesheet" type="text/css" href="{% static 'employee/style.css' %}">
|
58
|
+
|
59
|
+
<link rel="stylesheet" type="text/css" href="{% static 'employee/show.css' %}">
|
60
|
+
|
61
|
+
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
|
62
|
+
|
63
|
+
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
|
64
|
+
|
65
|
+
<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/pepper-grinder/jquery-ui.css">
|
66
|
+
|
67
|
+
|
68
|
+
|
51
69
|
<div class = top>
|
52
70
|
|
53
71
|
<h1>一覧</h1>
|
@@ -112,13 +130,99 @@
|
|
112
130
|
|
113
131
|
<td class="edit">
|
114
132
|
|
115
|
-
|
116
|
-
|
117
|
-
|
133
|
+
<button><a href="{% url 'employee:update' id=value.id %}"><img src="{% static "employee/update-btn.png" %}"></a></button>
|
134
|
+
|
118
|
-
|
135
|
+
<button id='del_btn' class='del_btn'><img src="{% static "employee/delete-btn.png" %}"></button>
|
136
|
+
|
137
|
+
<div id="dl2" style="display:none;">
|
138
|
+
|
139
|
+
<p>この行を削除しますか?</p>
|
140
|
+
|
141
|
+
<footer>
|
142
|
+
|
143
|
+
<button id='cancel_button'>いいえ</button>
|
144
|
+
|
145
|
+
<form name="delete_form" id="delete_form" method="post" action="{% url 'employee:delete' id=value.id %}"></form>
|
146
|
+
|
147
|
+
{% csrf_token %}
|
148
|
+
|
149
|
+
<button id='delete_button' type="submit">はい</button>
|
150
|
+
|
151
|
+
</form>
|
152
|
+
|
153
|
+
</footer>
|
154
|
+
|
155
|
+
</div>
|
156
|
+
|
157
|
+
</td>
|
158
|
+
|
159
|
+
</td>
|
160
|
+
|
161
|
+
</tr>
|
162
|
+
|
163
|
+
{% endfor %}
|
164
|
+
|
165
|
+
</table>
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
<script type="text/javascript">
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
$(function() {
|
174
|
+
|
175
|
+
$(".del_btn").click(function() {
|
176
|
+
|
177
|
+
$("#dl2").dialog({
|
178
|
+
|
179
|
+
modal:true,
|
180
|
+
|
181
|
+
title:"登録者情報の削除確認",
|
182
|
+
|
183
|
+
buttons: {
|
184
|
+
|
185
|
+
"はい": function() {$(this).dialog("close");},
|
186
|
+
|
187
|
+
"いいえ": function() {$(this).dialog("close");}
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
});
|
192
|
+
|
193
|
+
});
|
194
|
+
|
195
|
+
});
|
196
|
+
|
197
|
+
</script>
|
198
|
+
|
199
|
+
</div>
|
200
|
+
|
201
|
+
</div>
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
```
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
### 試したこと
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
```HTML
|
214
|
+
|
215
|
+
<!-- 更新と削除のボタン表示 -->
|
216
|
+
|
217
|
+
<td class="edit">
|
218
|
+
|
219
|
+
<button><a href="{% url 'employee:update' id=value.id %}"><img src="{% static "employee/update-btn.png" %}"></a></button>
|
220
|
+
|
119
|
-
|
221
|
+
<button id='del_btn' class='del_btn' onclick="clickDelete(id=value.id)"><img src="{% static "employee/delete-btn.png" %}"></button>
|
222
|
+
|
120
|
-
|
223
|
+
<form method="post" action="{% url 'employee:delete' id=value.id %}">
|
224
|
+
|
121
|
-
|
225
|
+
{% csrf_token %}
|
122
226
|
|
123
227
|
<dialog id='dialog'>
|
124
228
|
|
@@ -134,19 +238,13 @@
|
|
134
238
|
|
135
239
|
<button id='cancel_button'>いいえ</button>
|
136
240
|
|
137
|
-
<form name="delete_form" id="delete_form" method="post" action="{% url 'employee:delete' id=value.id %}"></form>
|
138
|
-
|
139
|
-
{% csrf_token %}
|
140
|
-
|
141
|
-
|
241
|
+
<button id='delete_button' type="submit">はい</button><!-- onclick='return confirm("この行を削除しますか?");' -->
|
142
|
-
|
143
|
-
</form>
|
144
242
|
|
145
243
|
</footer>
|
146
244
|
|
147
245
|
</dialog>
|
148
246
|
|
149
|
-
|
247
|
+
</form>
|
150
248
|
|
151
249
|
</td>
|
152
250
|
|
@@ -164,9 +262,7 @@
|
|
164
262
|
|
165
263
|
document.getElementById("dialog").style.display = "none";
|
166
264
|
|
167
|
-
|
168
|
-
|
169
|
-
function clickDelete(){
|
265
|
+
function clickDelete(id){
|
170
266
|
|
171
267
|
const dialog = document.getElementById("dialog");
|
172
268
|
|
@@ -184,124 +280,22 @@
|
|
184
280
|
|
185
281
|
|
186
282
|
|
187
|
-
document.getElementById("cancel_button").addEventListener('click',
|
283
|
+
document.getElementById("cancel_button").addEventListener('click',() =>{
|
284
|
+
|
285
|
+
return false;
|
188
286
|
|
189
287
|
dialog.style.display = "none";
|
190
288
|
|
191
|
-
return false;
|
192
|
-
|
193
|
-
})
|
289
|
+
})
|
194
|
-
|
195
|
-
|
290
|
+
|
196
|
-
|
197
|
-
document.getElementById("delete_form").submit(); <!-- ここのコードをどう記述すればいいか分かりません -->
|
198
|
-
|
199
|
-
});
|
200
|
-
|
201
|
-
}
|
291
|
+
}
|
202
292
|
|
203
293
|
|
204
294
|
|
205
295
|
</script>
|
206
296
|
|
207
|
-
</div>
|
208
|
-
|
209
|
-
</div>
|
210
|
-
|
211
297
|
```
|
212
298
|
|
213
|
-
|
214
|
-
|
215
|
-
### 試したこと
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
```HTML
|
220
|
-
|
221
|
-
<!-- 更新と削除のボタン表示 -->
|
222
|
-
|
223
|
-
<td class="edit">
|
224
|
-
|
225
|
-
<button><a href="{% url 'employee:update' id=value.id %}"><img src="{% static "employee/update-btn.png" %}"></a></button>
|
226
|
-
|
227
|
-
<button id='del_btn' class='del_btn' onclick="clickDelete(id=value.id)"><img src="{% static "employee/delete-btn.png" %}"></button>
|
228
|
-
|
229
|
-
<form method="post" action="{% url 'employee:delete' id=value.id %}">
|
230
|
-
|
231
|
-
{% csrf_token %}
|
232
|
-
|
233
|
-
<dialog id='dialog'>
|
234
|
-
|
235
|
-
<h3>登録者情報の削除確認</h3>
|
236
|
-
|
237
|
-
<div>
|
238
|
-
|
239
|
-
この行を削除しますか?
|
240
|
-
|
241
|
-
</div>
|
242
|
-
|
243
|
-
<footer>
|
244
|
-
|
245
|
-
<button id='cancel_button'>いいえ</button>
|
246
|
-
|
247
|
-
<button id='delete_button' type="submit">はい</button><!-- onclick='return confirm("この行を削除しますか?");' -->
|
248
|
-
|
249
|
-
</footer>
|
250
|
-
|
251
|
-
</dialog>
|
252
|
-
|
253
|
-
</form>
|
254
|
-
|
255
|
-
</td>
|
256
|
-
|
257
|
-
</td>
|
258
|
-
|
259
|
-
</tr>
|
260
|
-
|
261
|
-
{% endfor %}
|
262
|
-
|
263
|
-
</table>
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
<script>
|
268
|
-
|
269
|
-
document.getElementById("dialog").style.display = "none";
|
270
|
-
|
271
|
-
function clickDelete(id){
|
272
|
-
|
273
|
-
const dialog = document.getElementById("dialog");
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
if(dialog.style.display=="block"){
|
278
|
-
|
279
|
-
dialog.style.display = "none";
|
280
|
-
|
281
|
-
}else{
|
282
|
-
|
283
|
-
dialog.style.display = "block";
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
document.getElementById("cancel_button").addEventListener('click',() =>{
|
290
|
-
|
291
|
-
return false;
|
292
|
-
|
293
|
-
dialog.style.display = "none";
|
294
|
-
|
295
|
-
})
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
</script>
|
302
|
-
|
303
|
-
```
|
304
|
-
|
305
299
|
上記のように変更したところ『はい』・『いいえ』どちらでも削除されてしまう。かつテーブルの1番上のデータが削除されてしまう
|
306
300
|
|
307
301
|
### 補足情報(FW/ツールのバージョンなど)
|