Closed randycoulman closed 3 months ago
If I rename the field from active? to active, everything works as I'd expect.
Wow, that's odd behavior! Thanks for opening this issue @randycoulman.
I gave it a quick look, and it seems like this is a Floki issue.
Giving this a try:
test "floki doesn't accept ? in id" do
html = """
<div id="hello?">
Hello world
</div>
"""
text =
html
|> Floki.parse_fragment!()
|> Floki.find("#hello?")
|> Floki.text()
assert text =~ "Hello world"
end
That test fails because Floki.find/2
returns []
.
If we change that to drop the ?
, Floki finds the correct tag.
Would you be interested in opening an issue on Floki's repo?
Would you be interested in opening an issue on Floki's repo?
@randycoulman I went ahead and implemented the finding by [id='<id>']
. So I think this should now work in main
.
@germsvel I just now had a chance to test your fix, and was still getting the same error.
It looks like the same fix needs to be applied to Form.descendant_selector/1 as well.
Doing a quick search of the code suggests a couple of other places that might also need the same fix. I haven't seen evidence of them failing, and I didn't dig in deeply, so they may be fine.
Looks like GitHub doesn't give me permission to reopen this issue, so let me know if you'd like me to open a new one instead.
Thanks @randycoulman!
Just updated those spots to pass the id like that. Honestly, it's not ideal. Error messages are less nice (in my opinion). I wonder if it would be better to not support ?
in IDs, but since it seems to be valid HTML, I'm including it.
I think there are a few spots remaining, @germsvel
https://github.com/germsvel/phoenix_test/blob/86344236df2d5e63496a0b7d02b001beb90d8412/lib/phoenix_test/form.ex#L66 https://github.com/germsvel/phoenix_test/blob/86344236df2d5e63496a0b7d02b001beb90d8412/lib/phoenix_test/button.ex#L83
The first one is currently biting me. The unit test below should trigger the error.
test "issue with question mark form field" do
alias PhoenixTest.Field
alias PhoenixTest.Form
html =
"""
<form id="post-form">
<label>
<input type="hidden" name="post[done?]" value="false">
<input type="checkbox" id="post_done?" name="post[done?]" value="true">
Done?
</label>
</form>
"""
field = Field.find_input!(html, "Done?")
Form.find_by_descendant!(html, field)
end
Changing the selector to use the [id=...]
approach seems to fix it. If you prefer I open a new issue, just tell me. Thanks for the library, BTW.
@alecostard this got completely lost in my notifications. I didn't have any visibility, but just ran across it accidentally in my email.
I just fixed that in https://github.com/germsvel/phoenix_test/commit/a0a99a37c2a11c373aaa16cd0d22b47e7e121908
I'm building a form for bulk-updating the
active?
field on an entity (Fund
in the output below).The relevant part of the
render
function is:My
core_components.ex
is pretty much identical to that generated bymix phx.new
; I have definitely not modified the checkbox component.When I try to do
|> uncheck("Some fund name")
or|> check("Some other fund name")
, I get the following error:I tried debugging through what PhoenixTest was doing, at it looks like it's returning zero matches in
Query.find/2
. But there's obviously aninput
with the right ID that is nested inside the form, so I'm not sure why it isn't finding it like it should.If I rename the field from
active?
toactive
, everything works as I'd expect.I can share more example code if needed, but wanted to get this bug report in.