Skip to content

Commit a652f6e

Browse files
committed
prevent default event when press enter on textbox to search rfc title
1 parent e452514 commit a652f6e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

html/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ <h4 class="alert-heading">RFC文書を自動翻訳したページ一覧</h4>
5555
<div class="form-group">
5656
<label for="searchRfc">RFCタイトル検索 (英数字のみ)</label>
5757
<input type="text" class="form-control" id="searchRfc" aria-describedby="searchRfc" placeholder="Search title keywords" autofocus>
58+
<input type="text" name="dummy" style="display: none;"><!-- Enterで送信しないために必要 -->
5859
</div>
5960
</form>
6061

html/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class RfcUi {
230230

231231
document.addEventListener('DOMContentLoaded', function () {
232232
const rfcList = new RfcListUi();
233-
rfcList.dispInit();
233+
rfcList.setup();
234234
});
235235

236236

@@ -244,11 +244,13 @@ class RfcListUi {
244244
this.rfcSearchIndex = {};
245245
}
246246

247-
dispInit() {
247+
// 初期設定
248+
setup() {
248249
this._createIndex();
249250
// console.log("rfcSearchIndex:", this.rfcSearchIndex);
250-
const domSearchRfc = document.querySelector('#searchRfc')
251+
const domSearchRfc = document.querySelector('#searchRfc');
251252
if (domSearchRfc) {
253+
// RFCタイトル検索項目入力時のイベント登録
252254
domSearchRfc.addEventListener('input', () => {
253255
// 検索文字列が1文字以下のときは、抽出しない
254256
if (domSearchRfc.value.length <= 1) {
@@ -261,12 +263,14 @@ class RfcListUi {
261263
}
262264
}
263265

266+
// 検索処理
264267
_search(searchInput) {
265268
// console.log("searchText:", searchInput);
266269
const matchedRfcs = this._searchRfcSet(this._normalizeSearchWord(searchInput));
267270
this._renderRfcList(matchedRfcs);
268271
}
269272

273+
// 検索用インデックスの作成
270274
_createIndex() {
271275
document.querySelectorAll(RfcListUi.QUERYSELECTOR_RFCLIST_ITEM).forEach(el => {
272276
const rfcId = el.attributes["id"].value;
@@ -278,6 +282,7 @@ class RfcListUi {
278282
});
279283
}
280284

285+
// インデックスを利用した検索処理
281286
_searchRfcSet(searchInput) {
282287
const matchedRfcs = [];
283288
// 検索ワードをスペース区切りで抽出する(ただし空白は除外)
@@ -297,6 +302,7 @@ class RfcListUi {
297302
return new Set(matchedRfcs);
298303
}
299304

305+
// 指定したRFC一覧の描画
300306
_renderRfcList(rfcNumbers) {
301307
document.querySelectorAll(RfcListUi.QUERYSELECTOR_RFCLIST_ITEM).forEach(el => {
302308
const rfcId = el.attributes["id"].value;
@@ -309,12 +315,14 @@ class RfcListUi {
309315
});
310316
}
311317

318+
// RFC一覧の描画
312319
_renderRfcListAll() {
313320
document.querySelectorAll(RfcListUi.QUERYSELECTOR_RFCLIST_ITEM).forEach(el => {
314321
el.classList.remove(RfcListUi.CSSCLASS_HIDE);
315322
});
316323
}
317324

325+
// 検索キーワードの静音化
318326
_normalizeSearchWord(word) {
319327
return word.replace(/[-()/:]/, '')
320328
}

0 commit comments

Comments
 (0)