Cope with conditionally rendered form inputs#297
Open
s3cur3 wants to merge 2 commits intogermsvel:mainfrom
Open
Cope with conditionally rendered form inputs#297s3cur3 wants to merge 2 commits intogermsvel:mainfrom
s3cur3 wants to merge 2 commits intogermsvel:mainfrom
Conversation
This fixes an issue with `fill_in` where past input values were accumulated and then passed to `LiveViewTest.render_change/2` even when the input that would have produced the value was no longer present in the form. The change simply removes inputs whose `name` is no longer present in the form when using `fill_in`.
On a complicated form, you might have some inputs (say, a `<select>`) which conditionally hide other elements on the form. (One could argue that the unused inputs should merely be hidden, rather than removed from rendering in such cases, but on a sufficiently complicated form, it sometimes makes sense to truly remove the inputs.)
Prior to these changes, the newly added test would fail with a message like this:
```
1) test conditional form fields submitting after switching versions only includes the visible field (PhoenixTest.LiveTest)
test/phoenix_test/live_test.exs:1458
** (ArgumentError) could not find non-disabled input, select or textarea with name "version_a_text" within:
<select id="version" name="version"><option value="a">Version A</option><option value="b">Version B</option></select><input id="version_b_text" name="version_b_text"/>
code: |> fill_in("Version B Text", with: "some value for B")
stacktrace:
(phoenix_live_view 1.1.8) lib/phoenix_live_view/test/live_view_test.ex:1122: Phoenix.LiveViewTest.call/2
(phoenix_test 0.9.1) lib/phoenix_test/live.ex:460: PhoenixTest.Live.trigger_form_phx_change/3
test/phoenix_test/live_test.exs:1463: (test)
```
As a user, that error was quite confusing, because I said to myself "Well that doesn't make sense! I was trying to fill in 'Version B Text,' not `version_a_text` like the error message says!"
(With this change, that test simply passes.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes an issue with
fill_inwhere past input values were accumulated and then passed toLiveViewTest.render_change/2even when the input that would have produced the value was no longer present in the form. (The change simply removes inputs whosenameis no longer present in the form when usingfill_in.)On a complicated form, you might have some inputs (say, a
<select>) which conditionally hide other elements on the form. (One could argue that the unused inputs should merely be hidden, rather than removed from rendering in such cases, but on a sufficiently complicated form, it sometimes makes sense to truly remove the inputs.)Prior to these changes, the newly added test would fail with a message like this:
As a user, that error was quite confusing, because I said to myself "Well that doesn't make sense! I was trying to fill in 'Version B Text,' not
version_a_textlike the error message says!"(With this change, that test simply passes.)