mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 13:25:51 +03:00
[GH-ISSUE #137] We want FormItem to implement RemoveItem() so that we can remove input fields from a Form element. like how you can remove a primitive from a Flex or Grid object. #106
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#106
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 @melt7777 on GitHub (Jul 10, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/137
We want FormItem to implement RemoveItem() so that we can remove input fields from a Form element. like how you can remove a primitive from a Flex or Grid object.
Rationale: We want to use the FormItem Checkbox's callback function to add/remove other FormItem InputField elements on the Form based on IsChecked. Also, we notice that the IsChecked does not work on a Checkbox that is a FormItem. Is there a way to expose the functions that are part of the various Primitives even in their FormItem instance?
I see in https://github.com/rivo/tview/blob/master/form.go#L243 where we are using the items[] to store the items in the Form.
Until this could be done, I am thinking of a workaround: Manipulating Form.index[] directly. Do you think this is viable?
Many thanks!
melt
getpimp.org dev team
@rivo commented on GitHub (Jul 14, 2018):
I can certainly give you a
RemoveFormItem()function but it will be part of theFormclass. TheFormItemelements themselves don't keep a reference to their containingForm(and I believe they shouldn't) so you'll have to callRemoveFormItem()on the form itself. Would that work for you?I'm not sure what you mean by
Form.index[]. There isForm.itemsbut you won't have access to it from outside the package.Also, you mentioned that
IsChecked()does not work. I'm not sure why it wouldn't. Can you give a short example for this?@melt7777 commented on GitHub (Jul 14, 2018):
Yes, that would be great, just like we use var to declare the App and Flex objects to refer to them later, I can refer to, say, form.RemoveFormItem("Name:") to remove items.
Sorry, I meant items[] not index[]. Alright, that workaround won't work.
Essentially the reason for this is: I want to have a form with some InputFields, then a CheckBox, then some more InputFields. But I want to have a callback function that only shows the bottom group of fields when the CheckBox is not checked. Example:
Use DHCP: [ ] // when the box is not checked, show form elements 6,7,8, like:
Static IP:
....
Thank you very much for your great project. We hope to use it to make our applications very easy to use.
Let me know if additional information or explanation would help you with this feature.
@rivo commented on GitHub (Jul 17, 2018):
Please check out the latest version. To remove an item, you can now do the following:
Let me know if this helps you with your application.
@melt7777 commented on GitHub (Jul 17, 2018):
This works exactly as we needed. Thank you very much!