[GH-ISSUE #381] Help: show modal dialog on table view #281

Closed
opened 2026-03-04 01:03:35 +03:00 by kerem · 8 comments
Owner

Originally created by @labkode on GitHub (Dec 25, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/381

I'm creating an application based on the presentation tview demo.

I'm reusing the table code for one of the pages and I want that when I click 'e' on one of the table rows a modal appears to modify the row. I've done the logic capture the key event and perform any action but the modal is not showing.

	table.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
		selected, _ := table.GetSelectable()

		if event.Key() == tcell.KeyEnter {
			table.SetSelectable(true, true)
		}

		if selected && event.Key() == tcell.KeyRune && event.Rune() == 'e' {
			// find row
			row, col := table.GetSelection()
			cell := table.GetCell(row, col)

			modal := tview.NewModal().
				SetText("Name: " + cell.Text).
				AddButtons([]string{"Save", "Cancel"}).
				SetDoneFunc(func(buttonIndex int, buttonLabel string) {
					if buttonLabel == "Cancel" {
						app.Stop()
					}
				})
			app.SetFocus(modal)
			app.ForceDraw()
		}
		return event
	})

Thanks and Happy Christmas!

Originally created by @labkode on GitHub (Dec 25, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/381 I'm creating an application based on the presentation tview demo. I'm reusing the table code for one of the pages and I want that when I click 'e' on one of the table rows a modal appears to modify the row. I've done the logic capture the key event and perform any action but the modal is not showing. ``` table.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { selected, _ := table.GetSelectable() if event.Key() == tcell.KeyEnter { table.SetSelectable(true, true) } if selected && event.Key() == tcell.KeyRune && event.Rune() == 'e' { // find row row, col := table.GetSelection() cell := table.GetCell(row, col) modal := tview.NewModal(). SetText("Name: " + cell.Text). AddButtons([]string{"Save", "Cancel"}). SetDoneFunc(func(buttonIndex int, buttonLabel string) { if buttonLabel == "Cancel" { app.Stop() } }) app.SetFocus(modal) app.ForceDraw() } return event }) ``` Thanks and Happy Christmas!
kerem closed this issue 2026-03-04 01:03:35 +03:00
Author
Owner

@Bios-Marcel commented on GitHub (Dec 25, 2019):

The modal is just a primitive (Widget), you actually have to set it as the root layout primitive using Application#SetRoot.

<!-- gh-comment-id:568926371 --> @Bios-Marcel commented on GitHub (Dec 25, 2019): The modal is just a primitive (Widget), you actually have to set it as the root layout primitive using Application#SetRoot.
Author
Owner

@labkode commented on GitHub (Dec 25, 2019):

@Bios-Marcel that would break the existing layout.

<!-- gh-comment-id:568937448 --> @labkode commented on GitHub (Dec 25, 2019): @Bios-Marcel that would break the existing layout.
Author
Owner

@Bios-Marcel commented on GitHub (Dec 25, 2019):

Drawing things ontop of other things isn't supported afaik.

<!-- gh-comment-id:568938724 --> @Bios-Marcel commented on GitHub (Dec 25, 2019): Drawing things ontop of other things isn't supported afaik.
Author
Owner

@labkode commented on GitHub (Dec 26, 2019):

@Bios-Marcel is possible I just managed. The magic is to set the current view as the background of the modal.

Is explained here: https://github.com/rivo/tview/wiki/Modal

<!-- gh-comment-id:568944777 --> @labkode commented on GitHub (Dec 26, 2019): @Bios-Marcel is possible I just managed. The magic is to set the current view as the background of the modal. Is explained here: https://github.com/rivo/tview/wiki/Modal
Author
Owner

@Bios-Marcel commented on GitHub (Dec 26, 2019):

Oh cool, guess I learned something then, thanks ^^

<!-- gh-comment-id:569026381 --> @Bios-Marcel commented on GitHub (Dec 26, 2019): Oh cool, guess I learned something then, thanks ^^
Author
Owner

@agruenberg commented on GitHub (Jan 23, 2020):

Or you use pages, where you put the modal on top most.

<!-- gh-comment-id:577525592 --> @agruenberg commented on GitHub (Jan 23, 2020): Or you use pages, where you put the modal on top most.
Author
Owner

@LazarenkoA commented on GitHub (Jul 15, 2020):

@Bios-Marcel is possible I just managed. The magic is to set the current view as the background of the modal.

Is explained here: https://github.com/rivo/tview/wiki/Modal

Hi. I have a similar task, can you share the code? Have you used Pages (as in the demo)?

<!-- gh-comment-id:658777387 --> @LazarenkoA commented on GitHub (Jul 15, 2020): > @Bios-Marcel is possible I just managed. The magic is to set the current view as the background of the modal. > > Is explained here: https://github.com/rivo/tview/wiki/Modal Hi. I have a similar task, can you share the code? Have you used Pages (as in the demo)?
Author
Owner

@LazarenkoA commented on GitHub (Jul 15, 2020):

@Bios-Marcel is possible I just managed. The magic is to set the current view as the background of the modal.
Is explained here: https://github.com/rivo/tview/wiki/Modal

Hi. I have a similar task, can you share the code? Have you used Pages (as in the demo)?

made it using Pages

<!-- gh-comment-id:658786684 --> @LazarenkoA commented on GitHub (Jul 15, 2020): > > @Bios-Marcel is possible I just managed. The magic is to set the current view as the background of the modal. > > Is explained here: https://github.com/rivo/tview/wiki/Modal > > Hi. I have a similar task, can you share the code? Have you used Pages (as in the demo)? made it using Pages
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#281
No description provided.