LoginSignup
2
1

More than 3 years have passed since last update.

kintoneにボタンを置いて任意のフィールドをクリップボードにコピーする

Last updated at Posted at 2019-08-23

kintoneの詳細画面とかにボタンを置いて、押すと任意のフィールドをコピーする。

  • memo_markdownこの部分を任意のコピーしたいフィールドのフィールドコードに変更。
  • 「スペース」フィールドの配置が必要。今回はcopy_buttonというフィールドコードで配置。
  • jQueryは読み込み必要。
sample.js
(function($) {
  'use strict';
  let events = [
    'app.record.create.show',
    'app.record.edit.show',
    'app.record.detail.show'
  ]
  kintone.events.on(events, function(event){
    let el = kintone.app.record.getSpaceElement('copy_button');
    $('<input />', {
      'type': 'button',
      'name': 'c_button',
      'value': 'Copy',
      'class': 'create_button',
    }).on('click', function (resp) {
      let copyFrom = document.createElement("textarea");
      copyFrom.textContent = event.record.memo_markdown.value;
      let bodyElm = document.getElementsByTagName("body")[0];
      bodyElm.appendChild(copyFrom);
      copyFrom.select();
      document.execCommand('copy');
      alert("リリースノートをコピーしました。");
      bodyElm.removeChild(copyFrom);
    }).appendTo(el);
  });
})(jQuery);

2
1
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
2
1