mirror of
https://github.com/rivo/tview.git
synced 2026-04-27 05:45:49 +03:00
[GH-ISSUE #724] Feature Request/question: would it be worth to add a reference/id to form primitives? #531
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#531
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 @marioemmanuel on GitHub (Apr 16, 2022).
Original GitHub issue: https://github.com/rivo/tview/issues/724
While exploring tview as a data front end tool, I am finding myself writing sample code as:
customerForm.GetFormItemByLabel("VAT ID").(*tview.InputField).SetText(c.vatId));I am wondering if having an additional reference or id field (similar to what
ID HTML attributedoes for HTML front ends) would be helpful. In this case the name of the struct variable isc.vatId, but the label isVAT IDso somehow you need to handle both and if you decide to change the label that implies modifying more code.It would be easier if you could write something like:
customerForm.GetFormItemById("vatId").(*tview.InputField).SetText(c.vatId));The reason being that
c.vatIdcan be referenced using reflection asreflect.ValueOf(&c).Elem().FieldByName("vatId")which opens more potential to better organise the application without using frameworks or complex architectures.So we could separate the actual display label from the form field Id and just know that
"vatId"is the field both in our backend data structure and in the Form element.I know this could trigger many passionate opinions and unrequested dogmatic advises on how an application shall be architected -hopefully it does not-. The purpose of this comment is to raise the question on if "ids" could be helpful. To me they would be as you just need to reference fields by its Id both in the Form and in the underlying application data structures.
@marioemmanuel commented on GitHub (Apr 24, 2022):
Another two use cases where this is useful:
If you have "Address Line 1", "Address Line 2", "Address Line 3" you might want to add three input fields but just label the first "Address Line" and leave empty the other two. In that case having this "dummy" IDs would be good.
If you have an application where labels change depending on the language selected, having a common "dummy" ID to retrieve an exact form element is really helpful.
The "dummy" ID would not require any special logic as it is just another way to reference an item, and it would provide the same utility that the HTML ID attribute.
@rivo commented on GitHub (Dec 17, 2022):
I agree that selecting items by label is not optimal, specifically for your second point. (Although I do wonder if you are actually having that problem in an application of yours or whether you listed a problem that "might" occur some time in the future. I have not had any other complaints about this yet.)
The first point can now be solved by adding a
TextAreato theForm.So yes, in retrospect, I would do it differently, and an ID would be a possible solution. But now I need to think about backwards compatibility. The
Add...methods cannot be changed. And adding new versions for all of them on top is also not something I want to do. Currently, I cannot think of a good way to add IDs.Alternatively, I could easily add a
GetItemByIndex(index)function. This would not be as clean as ID strings but it could solve the issue where you cannot rely on labels.@SamWhited commented on GitHub (Dec 17, 2022):
FWIW, I have also run into this exact problem a number of times in real world applications and ended up using custom lists or another UI toolkit in several cases. I thought I had filed an issue about this as well, but I guess not.
@marioemmanuel commented on GitHub (Jan 21, 2023):
To me it was the reason for withdraw the toolkit. I was doing a sample toy application, nothing commercial or serious.