[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

Closed
opened 2026-03-04 01:01:59 +03:00 by kerem · 4 comments
Owner

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

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
kerem closed this issue 2026-03-04 01:02:00 +03:00
Author
Owner

@rivo commented on GitHub (Jul 14, 2018):

I can certainly give you a RemoveFormItem() function but it will be part of the Form class. The FormItem elements themselves don't keep a reference to their containing Form (and I believe they shouldn't) so you'll have to call RemoveFormItem() on the form itself. Would that work for you?

I'm not sure what you mean by Form.index[]. There is Form.items but 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?

<!-- gh-comment-id:405015928 --> @rivo commented on GitHub (Jul 14, 2018): I can certainly give you a `RemoveFormItem()` function but it will be part of the `Form` class. The `FormItem` elements themselves don't keep a reference to their containing `Form` (and I believe they shouldn't) so you'll have to call `RemoveFormItem()` on the form itself. Would that work for you? I'm not sure what you mean by `Form.index[]`. There is `Form.items` but 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?
Author
Owner

@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.

<!-- gh-comment-id:405016426 --> @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.
Author
Owner

@rivo commented on GitHub (Jul 17, 2018):

Please check out the latest version. To remove an item, you can now do the following:

form.RemoveFormItem(form.GetFormItemIndex("Name:"))

Let me know if this helps you with your application.

<!-- gh-comment-id:405679789 --> @rivo commented on GitHub (Jul 17, 2018): Please check out the latest version. To remove an item, you can now do the following: ```go form.RemoveFormItem(form.GetFormItemIndex("Name:")) ``` Let me know if this helps you with your application.
Author
Owner

@melt7777 commented on GitHub (Jul 17, 2018):

This works exactly as we needed. Thank you very much!

<!-- gh-comment-id:405687193 --> @melt7777 commented on GitHub (Jul 17, 2018): This works exactly as we needed. Thank you very much!
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#106
No description provided.