LoginSignup
0
0

More than 5 years have passed since last update.

kintone プラグイン開発メモ その5(設定画面で保存した値を読み込んでみる)

Last updated at Posted at 2019-01-23

今回は、設定画面で保存した値を一覧画面で読み込んでみたいと思います。

流れ

  1. 設定画面を作成
  2. 設定画面で入力した値を保存
  3. 一覧画面で保存した値を読み込んで表示

ソースコード

プラグイン設定画面

config.html
<html>
    <body>
        <h1>Hello,world設定画面</h1>
        <div id="form">
            <div>
                <label for="text">名前を入力:</label>
                <input type="text" id="name">
            </div>
            <div>
                <label for="text">今日の運勢を入力:</label>
                <input type="text" id="unsei">
            </div>
                <div class="button">
                <button type="button" id="button_submit">保存</button>
            </div>
        </div>
    </body>
</html>

プラグインJS

config.js
(function (pluginId) {
    "use strict";
    window.addEventListener('DOMContentLoaded', function() {
        console.log(kintone.plugin.app.getConfig(pluginId));
        document.getElementById("button_submit").onclick = function() {
            let elName = document.getElementById("name");
            let elUnsei = document.getElementById("unsei");
            let config = {
                "name": elName.value,
                "unsei": elUnsei.value
            };
            kintone.plugin.app.setConfig(config);
            window.alert("保存しました");
        };
    });

})(kintone.$PLUGIN_ID);

アプリ用JS

customize.js
(function(pluginId) {
    "use strict";
    let config = kintone.plugin.app.getConfig(pluginId)
    console.log(config);
    kintone.events.on('app.record.index.show', function(event) {
        window.alert('Hello,' + config["name"] + 'さん! 今日の運勢は、' + config["unsei"] + 'ですね!');
    });
})(kintone.$PLUGIN_ID);

ひとまずプラグインで保存した値を読み込むまでやってみました。
実際に使うためには入力値をチェックする等のセキュリティが必要だと思いますので、そのあたりも調べていきたいと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0