質問編集履歴
3
回答用のエラー画像の追加
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
kabootstrapにてCtrl + Enter でSubmitボタンを押すようにしたい。
|
body
CHANGED
@@ -144,4 +144,9 @@
|
|
144
144
|
生成されたhtml
|
145
145
|

|
146
146
|
|
147
|
-
なにかご教授いただければ幸いです。
|
147
|
+
なにかご教授いただければ幸いです。
|
148
|
+
|
149
|
+
---
|
150
|
+
|
151
|
+
回答用1
|
152
|
+

|
2
生成されたhtmlを追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -141,4 +141,7 @@
|
|
141
141
|
...
|
142
142
|
```
|
143
143
|
|
144
|
+
生成されたhtml
|
145
|
+

|
146
|
+
|
144
147
|
なにかご教授いただければ幸いです。
|
1
bootstrapの複数行入力可能なフォームはCtrl + Enterによるsubmitに対応していないみたいなので、JQueryを利用する方式にしましたがうまくいきません。
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,8 +4,7 @@
|
|
4
4
|
|
5
5
|
## 現状
|
6
6
|
|
7
|
-
bootstrapのテンプレートサイトを見ると、form入力後Ctrl + Enterを押すとsubmitされるが、
|
8
|
-
|
7
|
+
console.logのsubmit!!!!はログに出力されるが、実際にpostが実行されない。
|
9
8
|
|
10
9
|
## 環境
|
11
10
|
|
@@ -21,6 +20,23 @@
|
|
21
20
|
{% extends "layout.html" %}
|
22
21
|
{% block content %}
|
23
22
|
<!--{% import "bootstrap/wtf.html" as wtf %}-->
|
23
|
+
<script>
|
24
|
+
$(function(){
|
25
|
+
//テキストエリアがアクティブの状態にキーが押されたらイベントを発火
|
26
|
+
$('#post').keydown(function(e){
|
27
|
+
//ctrlキーが押されてる状態か判定
|
28
|
+
if(event.ctrlKey){
|
29
|
+
//押されたキー(e.keyCode)が13(Enter)か そしてテキストエリアに何かが入力されているか判定
|
30
|
+
if(e.keyCode === 13 && $(this).val()){
|
31
|
+
console.log("submit!!!!");
|
32
|
+
//フォームを送信
|
33
|
+
$('#submit').submit();
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
});
|
38
|
+
});
|
39
|
+
</script>
|
24
40
|
|
25
41
|
<form class="form form-horizontal" method="post" role="form">
|
26
42
|
{{ form.csrf_token() }}
|
@@ -28,6 +44,15 @@
|
|
28
44
|
{{ wtf.form_field(form.submit, class="btn btn-primary")}}
|
29
45
|
</form>
|
30
46
|
|
47
|
+
|
48
|
+
<form>
|
49
|
+
<div class="form-group">
|
50
|
+
<label for="exampleFormControlTextarea1">Example textarea</label>
|
51
|
+
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
|
52
|
+
</div>
|
53
|
+
<button type="submit" class="btn btn-primary">Submit</button>
|
54
|
+
</form>
|
55
|
+
|
31
56
|
<hr>
|
32
57
|
|
33
58
|
{% for note in notes%}
|
@@ -63,7 +88,6 @@
|
|
63
88
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
64
89
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
65
90
|
<!-- Bootstrap4:END -->
|
66
|
-
<script type="text/javascript" src="../static/js/keyEvent.js"></script>
|
67
91
|
</head>
|
68
92
|
<body>
|
69
93
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|