Created
January 4, 2024 02:44
-
-
Save motohasystem/a3fbcaa01327dcf500f1d94c1403d563 to your computer and use it in GitHub Desktop.
kintoneに小さな機能を追加するJavaScriptカスタマイズ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* このJavaScriptコードは、kintoneの一覧画面のヘッダースペースにテキストフィールドと送信ボタンを追加します。 | |
テキストフィールドの初期値は、ページURLのGETパラメータ「q」から取得した値に設定されています。 | |
ユーザーがこのフィールドに値を入力し、「送信」ボタンをクリックすると、 | |
その入力値が新しいGETパラメータ「q」としてURLにセットされ、ページがリロードされます。 | |
テキストフィールドの幅はヘッダースペースの60%に設定されており、視覚的にバランスが取れていて使いやすいデザインになっています。 | |
このカスタマイズにより、ユーザーは簡単に特定の情報をURLに組み込むことができ、ページをリロードすることで | |
その情報に基づいたビューの更新や処理を実行できます。 | |
*/ | |
(function() { | |
"use strict"; | |
kintone.events.on('app.record.index.show', function(event) { | |
var headerSpace = kintone.app.getHeaderSpaceElement(); | |
// URLからGETパラメータを取得 | |
var urlParams = new URLSearchParams(window.location.search); | |
var qParam = urlParams.get('q') || ''; | |
// テキストフィールドの作成と初期値、スタイルの設定 | |
var inputField = document.createElement('input'); | |
inputField.type = 'text'; | |
inputField.value = decodeURIComponent(qParam); // GETパラメータの値をデコードしてセット | |
inputField.style.width = '60%'; // 幅を60%に設定 | |
inputField.style.marginRight = '10px'; | |
// ボタンの作成 | |
var submitButton = document.createElement('button'); | |
submitButton.innerText = '送信'; | |
submitButton.onclick = function() { | |
// 入力された値をURLのGETパラメータとしてセット | |
var inputValue = encodeURIComponent(inputField.value); | |
var newUrl = window.location.origin + window.location.pathname + '?q=' + inputValue; | |
window.location.href = newUrl; // ページをリロード | |
}; | |
// ヘッダーにフィールドとボタンを追加 | |
headerSpace.appendChild(inputField); | |
headerSpace.appendChild(submitButton); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment