How to add a custom button to the edit dialog and how to get and set the value of a text box within the edit dialog

Hi,

I want to add a custom button to the edit dialog that, when clicked, copies the value from one text box to another text box.

I was able to add a button to the edit dialog, but I don't know the proper way to get and set the value of the text box within the edit dialog.

What is the appropriate way to implement this?

I'd also like to know if the method shown in the sample code for adding a custom button to the edit dialog is correct.


sample: add customButton to edit dialog - StackBlitz


6 Replies

AK Akira Kume December 10, 2025 02:00 AM UTC

In addition to the above, I would like to know if there is a way to align the COPY button to the left.



SJ Sridharan Jayabalan Syncfusion Team December 11, 2025 11:32 AM UTC

Hi Akira,

Greetings from Syncfusion.
Currently, the Gantt chart’s Edit Dialog does not include a built‑in “Copy to clipboard” action for field values. However, you can achieve this through a simple customization using the actionBegin and actionComplete events of the Gantt component, along with a small clipboard routine and CSS-based alignment.
What we do:
  • Use actionBegin (beforeOpenEditDialog) to inject a custom COPY button into the dialog’s footer.
  • Use actionComplete (openEditDialog) to:
    • Visually align the COPY button to the far-left using Flexbox (order: -1 + margin-right: auto).
    • Track the last interacted field’s value inside the dialog so the COPY button can copy exactly what the user selected/edited.
Behavior for end users:
  1. Open the Edit dialog for a task.
  2. The footer displays COPY on the left, and Save/Cancel on the right.
  3. Click COPY → the selected field’s value is placed on the clipboard.
  4. Paste anywhere using Ctrl + V.

Code-Snippet:   

index.js:-


function App() {
  const ganttRef = useRef(null);
  let copiedValue;


  const actionBegin = (args) => {
    if (args.requestType === 'beforeOpenEditDialog') {
      const rowData = args.rowData;

      args.dialogModel.buttons.push({
        buttonModel: { content: 'COPY', id: 'customCopy' },
        click: async () => {
          const textToCopy =
            typeof copiedValue === 'string' && copiedValue.trim()
              ? copiedValue.trim()
              : rowData?.taskName ?? '';

          if (!textToCopy) {
            alert('Nothing to copy');
            return;
          }

          let copied = false;
          if (!copied) {
            const ta = document.createElement('textarea');
            ta.value = textToCopy;
            ta.style.position = 'fixed';
            ta.style.top = '0';
            ta.style.left = '0';
            ta.style.opacity = '0';
            document.body.appendChild(ta);
            ta.focus();
            ta.select();
            try {
              const ok = document.execCommand('copy');
              if (!ok) throw new Error('execCommand("copy") failed');
              copied = true;
            } catch (err) {
              console.error('Fallback copy failed:', err);
            } finally {
              document.body.removeChild(ta);
            }
          }

          alert(
            copied
              ? 'Copied! You can press Ctrl+V to paste.'
              : 'Copy failed. Your environment blocks clipboard-write. The fallback also failed.'
          );
        },
      });
    }
  };

  const actionComplete = (args) => {
    // Only attach after Edit Dialog opens
    if (args.requestType === 'openEditDialog' && args.element) {
      // setting the COPY button on left
      const footer = args.element.querySelector('.e-footer-content');
      if (footer) {
        footer.style.display = 'flex';
        const copyBtn = footer.querySelector('button:nth-of-type(3)');
        if (copyBtn) {
          copyBtn.style.order = -1;
          copyBtn.style.marginRight = 'auto';
        }
      }

      const formRow = document
        .getElementById(args.element.id)
        ?.querySelector('.e-edit-form-row');

      // collecting the text box field value here
      formRow?.addEventListener('click', (e) => {
        const target = e.target;
        target.addEventListener('focusout', (e) => {
          if (target && target.classList?.contains('e-control')) {
            // e-control matches Syncfusion inputs
            copiedValue = target.value ?? '';
          } else {
            copiedValue = '';
          }
        });
      });
    }
  };

  return (
    <GanttComponent
      actionComplete={actionComplete}
      actionBegin={actionBegin}
    >
    </GanttComponent>
  );
}

 

Sample - https://stackblitz.com/edit/react-wrbgsnq3-xdpbsyec?file=index.js%3AL18


If we misunderstood your query, share us detailed information with screenshot or video.


 

Regards,

Sridharan



AK Akira Kume December 15, 2025 04:47 AM UTC

Hi,

Thank you for your reply.

I apologize for not conveying my question correctly, as I am using a translation service.

The copy function I want to implement is as follows.


1.Open the edit dialog

Image_2511_1765773000409


2.Overwrite the value in the taskName text box. (In some cases, it may not be rewritten.)

Image_4030_1765773122557


3.When you press the Copy button, the value in the taskName text box is copied to the additionalData text box.

Image_9590_1765774055386



SJ Sridharan Jayabalan Syncfusion Team December 15, 2025 02:03 PM UTC

Akira,

We understood your query: when selecting a text box and clicking the COPY button, the selected value should be pasted into the custom field additionalData, as shown in your shared screenshot.
We have modified the sample by setting the copiedValue to the additionalData field instance. Please refer to the sample and the code snippet below for your reference.

Code-Snippet:   

  const actionBegin = (args) => {
    if (args.requestType === 'beforeOpenEditDialog') {
      const rowData = args.rowData;

      args.dialogModel.buttons.push({
        buttonModel: { content: 'COPY', id: 'customCopy' },
        click: async () => {
          const textToCopy =
            typeof copiedValue === 'string' && copiedValue.trim()
              ? copiedValue.trim()
              : rowData?.taskName ?? '';

          if (!textToCopy) {
            alert('Nothing to copy');
            return;
          }
          let customFIeldInstance = document.getElementById(
            ganttRef.current.element.id + 'additionalData'
          ).ej2_instances[0]; //additionalData is column field name
          customFIeldInstance.value = copiedValue;
        },
      });
    }
  };

 

Modified Sample - add customButton to edit dialog (duplicated) - StackBlitz


Regards,

Sridharan



AK Akira Kume December 16, 2025 01:20 AM UTC

I was able to implement the desired functionality.

Thank you.



DS Deepika Sekar Syncfusion Team December 16, 2025 04:38 AM UTC

Hi Akira,

Thanks for the update! Please get back to us if you need any further assistance.

Regards,

Deepika S


Loader.
Up arrow icon