Closed vtm9 closed 6 years ago
(I'm thinking this through, so sorry if it rambles a bit...)
I understand what you are asking for. Is the button link powered by javascript that you wrote or a commonly used library? When I want a button that acts like a link, I usually apply "btn" classes to the link via Bootstrap, which works without the use of javascript to make the link work.
I'm open to adding follow_button, or something like that. Don't think we should overload follow_link with buttons.
The thing is that following a button pretty much requires javascript unless the data-method / data-to attributes are standard enough now that we can rely on them without breaking under lots of implementations. Thus, why I was asking about what library you are using.
Let me know your thoughts here. Lets see if we can come up with a generic enough solution.
I am using standart phoenix_html js package and helper button/2 in html.
It works good for simple interfaces. I think for this code
<button
class="btn btn-info btn-block"
data-csrf="csrf=="
data-method="post"
data-to="/test?level=test"
role="button">Test</button>
We could provide function click_button(conn, "Test")
, which find button in html by name and send request to data-to
path and data-method
method with data-csrf
param.
Maybe iplement function click_button(conn, "button_name", %{url: "data-to", method: "data-method", token: "data-csrf"})
which find button in html and try to find opts in button attributes.
That's pretty standard! Maybe I'll start using it too.
Yes. I think adding both click_button and follow_button functions is the way to go.
I've been in that code in the past few days, so I'll take a crack at it.
Cool, becase now in integration tests I am hand-parse the html in response, find button attributes and then make post-request
.
:+1:
OK. Should be in master. Can you please sync up to it and see if that does the trick for you?
I'm going to fix the other issue, which has been bugging me, while I'm here. So will push to hex after that is done and you confirm this works...
use this in deps to get the version from master...
{:phoenix_integration, git: "https://github.com/boydm/phoenix_integration.git" }
Ok I'll try
Thanks, it works good!
But I need to specify method click_button("Test", method: :post)
and get
is default
Is it possible to take method at data-method
attribute by default?
Good point. I'll take a look.
Should now get the method from the button's data-method
attribute unless it is otherwise specified in master.
Please update again and let me know how that works for you.
Ok
It's work great! Thanks!!!
Great. I'm going to close this issue and will probably push 0.5.0 out to hex later today or tomorrow.
Thank you much for the quick turn around testing and all that on this.
Thank you for the speed! Maybe you should update Readme and add there info about buttons.
Already added them to the documentation. I'll sprinkle sample calls into the readme too.
0.5.0 is pushed to hex.
{:phoenix_integration, "~> 0.5", only: :test}
Hi! I have html like this:
As I understand
follow_link
andclick_link
maethods works only with<a>
tags. (Floki.find(html, "a")
)Is there any way to follow the buttons?
I can make PR, if this functionality is missing. Thanks all!