Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set field results when form inputs are created with values #189

Open
mattngu01 opened this issue Apr 12, 2024 · 0 comments
Open

Set field results when form inputs are created with values #189

mattngu01 opened this issue Apr 12, 2024 · 0 comments
Labels
enhancement New feature or request input question Further information is requested

Comments

@mattngu01
Copy link

Is your feature request related to a problem? Please describe.
I am currently unit testing my TUI application using bubbletea. I found it unintuitive that when setting a field's value, you cannot immediately retrieve the results after creating a form.

func TestFilledForm(t *testing.T) {
	event := sampleEvent()
	f := filledEventForm(EventWrapper{&event})

	// huh forms do not set the results until processing nextFieldMsg through all fields
	for i := 0; i < 50; i++ {
		f.Update(f.NextField())
	}

	if f.GetString("summary") != event.Summary {
		t.Errorf("Summary: %v != %v", f.Get("summary"), event.Summary)
	}

	if f.GetString("description") != event.Description {
		t.Errorf("Description: %v != %v", f.Get("description"), event.Summary)
	}

	if f.GetString("start") != event.Start.DateTime {
		t.Errorf("Start: %v != %v", f.Get("start"), event.Start.DateTime)
	}

	if f.GetString("end") != event.End.DateTime {
		t.Errorf("End: %v != %v", f.Get("end"), event.End.DateTime)
	}

	if f.GetString("location") != event.Location {
		t.Errorf("Location: %v != %v", f.GetString("location"), event.Location)
	}
}

Describe the solution you'd like
A clear and concise description of what you want to happen.

Within NewForm(), I would like to set the results to any existing values for fields within it.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

I can always call NextField() in the Form setup for my unit tests, but I figure this behavior might confuse some users in the future.

Additional context

I just want to make sure if there is a specific choice for forms to work this way. If it is not intended, I can take a stab at it. I'm learning Go right now, and I think it would be a good opportunity.

@caarlos0 caarlos0 added enhancement New feature or request input question Further information is requested labels Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request input question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants