- Home
- Forum
- React - EJ 2
- 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
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.
In addition to the above, I would like to know if there is a way to align the COPY button to the left.
actionBegin and actionComplete events of the Gantt component, along with a small clipboard routine and CSS-based alignment.- 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.
- Implement a clipboard copy using a safe fallback (
document.execCommand('copy')).
- Open the Edit dialog for a task.
- The footer displays COPY on the left, and Save/Cancel on the right.
- Click COPY → the selected field’s value is placed on the clipboard.
- 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
Regards,
Sridharan
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
2.Overwrite the value in the taskName text box. (In some cases, it may not be rewritten.)
3.When you press the Copy button, the value in the taskName text box is copied to the additionalData text box.
additionalData, as shown in your shared screenshot.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
I was able to implement the desired functionality.
Thank you.
Hi Akira,
Thanks for the update! Please get back to us if you need any further assistance.
Regards,
Deepika S
- 6 Replies
- 3 Participants
-
AK Akira Kume
- Dec 9, 2025 07:20 AM UTC
- Dec 16, 2025 04:38 AM UTC