Customize button to add data

Question / Problem

I want to add a text box every time I click the button.
My custom button disappears when I save it.


(function() {
  'use strict';
  kintone.events.on('app.record.create.show', function(event) {
    // Create the first button
    var button1 = document.createElement('button');
    button1.id = 'button1';
    button1.innerHTML = '計數';

    // Run code when the button is clicked
    button1.onclick = function() {
      // Create text box
      // 生成文本框
      var textField = document.createElement('input');
      textField.type = 'text';
      textField.placeholder = '输入计数值';

      // Add text box to space element
      // 将文本框添加到空间元素中
      kintone.app.record.getSpaceElement('btn1').appendChild(textField);
    };

    // Set button1 on the first Blank space field
    kintone.app.record.getSpaceElement('btn1').appendChild(button1);

    // Create the second button
    var button2 = document.createElement('button');
    button2.id = 'button2';
    button2.innerHTML = '計量';

    // Run code when the button is clicked
    button2.onclick = function() {
      var record_data = kintone.app.record.get();
      alert(record_data.record.Created_datetime.value);
    };

    // Set button2 on the second Blank space field
    kintone.app.record.getSpaceElement('btn2').appendChild(button2);

    // Create the third button
    var button3 = document.createElement('button');
    button3.id = 'button3';
    button3.innerHTML = '測缸計';

    // Run code when the button is clicked
    button3.onclick = function() {
      var record_data = kintone.app.record.get();
      alert(record_data.record.Created_datetime.value);
    };

    // Set button3 on the third Blank space field
    kintone.app.record.getSpaceElement('btn3').appendChild(button3);

    // Create the fourth button
    var button4 = document.createElement('button');
    button4.id = 'button4';
    button4.innerHTML = '測相異位置';

    // Run code when the button is clicked
    button4.onclick = function() {
      var record_data = kintone.app.record.get();
      alert(record_data.record.Created_datetime.value);
    };

    // Set button4 on the fourth Blank space field
    kintone.app.record.getSpaceElement('btn4').appendChild(button4);

  });
})();

Hello @Jiatai_Lin , welcome to the community!

The custom buttons disappear after the record is saved is likely because the script that generates and appends these buttons is only attached to the 'app.record.create.show' event. This event is triggered only when a new record creation form is displayed. Once the record is saved, the buttons won't reappear unless the code is also attached to other events relevant to viewing or editing records.

To fix this, you should attach the button creation code to additional events, such as those triggered when the record is edited or displayed.