Skip to content

Do not duplicate dropdown option entry if it already exists#175

Closed
joakim-ribier wants to merge 1 commit intorivo:masterfrom
joakim-ribier:feature/dropdown-add-option-entry-if-not-already-exists
Closed

Do not duplicate dropdown option entry if it already exists#175
joakim-ribier wants to merge 1 commit intorivo:masterfrom
joakim-ribier:feature/dropdown-add-option-entry-if-not-already-exists

Conversation

@joakim-ribier
Copy link
Copy Markdown

Hi,

I propose this little fix (feature) for to not add a duplicate entry to a dropdown widget if the text already exists.

Sorry for advance, i don't know if this is the right way to proceed...

Thanks

@rivo
Copy link
Copy Markdown
Owner

rivo commented Oct 29, 2018

Hi, thank you for contributing to tview.

I have trouble understanding why you would like this functionality to be part of this package. I am not sure that users will expect this behaviour from the DropDown primitive.

Maybe you could provide an example where the current tview implementation was giving you headaches and we'll take it from there.

@joakim-ribier
Copy link
Copy Markdown
Author

Hi,

Actually, there is no directly a problem with the lib, i just thought it was more convenient to avoid entry duplicates directly in the primitive and not in my app side...

It's a bit heavy for each dropdown to check that it is not possible to add twice the same value :-)

@rivo
Copy link
Copy Markdown
Owner

rivo commented Oct 30, 2018

I can't think of a situation where one would accidentally add the same value twice. Can you give me an example where this happens for you?

@joakim-ribier
Copy link
Copy Markdown
Author

Hi,
Yes, of course i can 😃!

For the little context, to make my first app with the Go language, i try to impement my first text ui application with tview library.

It's a rich http client. So, my user needs to add header value in his request. For that, i implement a dropdown which list header values and an inputtext for adding a new value by the user.

So, if user adds twice the same value (for example my user clicks twice on "save" button on first screenshot), then, the dropdown contains now, several times the x value.

I think it's my own problem and not a library specifc solution for that...maybe the user may want a duplicate or not entry in the dropdown primitive 👍

You can close the PR 😃

form to add new value
add-new-values

example of dropdown values
list-new-values

@rivo
Copy link
Copy Markdown
Owner

rivo commented Nov 12, 2018

I would actually agree with you here that this functionality should be part of your application rather than the tview package. You could have a set like this:

set := make(map[string]struct{})

Then you also add your entry to this set: set[option] = struct{}{}. To test if an entry already exists, do this: _, exists := set[option]. If exists == true, you don't add your entry.

I'll close this PR now. If you have any more questions, feel free to post them here. I read them.

@rivo rivo closed this Nov 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants