mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #94] Feature Request: Improve method of retrieving form input #74
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#74
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @joegrasse on GitHub (Mar 30, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/94
It would be a lot easier to work with forms if you could get the input by name.
For example
@rivo commented on GitHub (Apr 1, 2018):
I don't know. I guess. But the way it is now, I'd either have to duplicate a whole bunch of
Formmethods or break backwards compatibility to achieve this (i.e. by adding a name parameter to allAddmethods).I would suggest that you do this:
Then you can always reference it by its actual variable
firstNameand you don't even have to cast it:If it's just about getting the input field's text, I usually use the event callback to update its string variable:
Would this help you?
@joegrasse commented on GitHub (Apr 1, 2018):
Yes, that is what I do now in the
form.AddButton("Save", func() {section. This makes it hard to break the code out that performs the save functionality though. I would have to pass all of the form items to the function, or dofirstname := form.GetFormItem(0).(*tview.InputField).GetText(). As you can see, 0 mapping to firstname isn't quite obvious.Also, I guess what I really meant was
firstname := form.GetFormItemByLabel("firstname").(*tview.InputField).GetText(). This wouldn't break backwards compatibility, since the Add* methods have a label.@rivo commented on GitHub (Apr 5, 2018):
Yeah, that's what I was going to offer you. I hope I'll have this for you tomorrow at the latest.
@joegrasse commented on GitHub (Apr 5, 2018):
Awesome. Thank you.
@rivo commented on GitHub (Apr 7, 2018):
Have a look, it's there now.
@joegrasse commented on GitHub (Apr 8, 2018):
Thanks again.
@joegrasse commented on GitHub (Apr 9, 2018):
@rivo I have been testing out your changes and have ran into an issue. After the form has been drawn, the label can change. As-in, it can have spaces added to it to line up all of the input boxes. Here you are updating the item attributes and above you are adding spaces to the label if needed. So the label doesn't always match what you set it to, which make
GetFormItemByLabelhard to use at the moment.@joegrasse commented on GitHub (Apr 9, 2018):
@rivo Created pull request to fix my issue.
@rivo commented on GitHub (Apr 9, 2018):
Please see my comments there.