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

Display field hints on nested forms #2804

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

sergioisidoro
Copy link
Contributor

@sergioisidoro sergioisidoro commented Mar 11, 2025

Currently the filed hints work on the application/_form.html.erb, but when a nested form is used, they are not displayed.

This is basically copying those lines from the form partial, with the difference that we're using f.object_nameinstead.

@nickcharlton
Copy link
Member

Could you look into adding a test to cover the change?

@sergioisidoro
Copy link
Contributor Author

sergioisidoro commented Mar 20, 2025

@nickcharlton I would appreciate some help in setting up the tests.

I was trying to add them to spec/administrate/views/fields/has_one/_form_spec.rb but that spec is really limited, it only tests that the has one renders the title. I'm unsure how to expand that example. Also nested_form seems to be an instance of Page::View instead of Page::Form.

Another alternative would be to add it to spec/features/form_spec.rb but the test dashboard does not have any HasOne field. I wonder if I should expand the test coverage there instead?

Some guidance?

Edit: I think I got it. I was really unable to expand on the _form_spec.rb because to render a field in that spec it would require quite a lot of mocking objects and their behaviour. The product form spec already had a has_many test for translating labels, so I added it there.

@nickcharlton
Copy link
Member

Oh, nice one! Yeah, you've got it here. I'd expect that we'd end up with a feature test for this, as otherwise as you notice we end up mocking out loads and that's not very nice.

Currently field hints work on the `application/_form.html.erb`, but
when a nested form is used, they are not displayed.

This is basically copying those lines from the form partial, with the
difference that we're using `f.object_name` instead.
@nickcharlton nickcharlton merged commit dd4737e into thoughtbot:main Mar 25, 2025
25 checks passed
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