Method: :delete is not working in multiple locations in my phoenix app

I fixed the JS errors with code mirror, but the delete is still not working

I am getting this error which I think is what is causing the issue

Uncaught SyntaxError: Unexpected string

In my app.js at -
import “phoenix_html”

Any idea whats wrong here?

Uh, that does not seem right
 Do you have a complete reproducible minimal example we can try?

It doesn’t need to be a full project, just a website you have set up that we can go to to try it.

I can provided you access to the app I’m working on via bitbucket just send me your email address. Will that work?

I would prefer just a quick thrown-up example page if possible though, to make sure of no outside interference?

Will try creating a new project but I’m pretty sure it’s how my project is built I think something to do with how I’m loading two different designed templates and JS but I’m not getting an errors so it’s a bit hard to debug.

Almog

I’m not getting the JS error anymore attached gif showing whats happing, thinking it’s an issue with the core lib what are your thoughts

Hmm, nothing in the console which clicking the delete button Open the inspecter there on the delete element and see what all event handlers are attached to it?

This is the code

 <%= link to: magnet_path(@conn, :delete, magnet), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-icon-toggle btn-refresh" do %>
                                            <span class="md md-delete"></span>
                                        <% end %>

And this is from the inspect

<a class="btn btn-icon-toggle btn-refresh" data-confirm="Are you sure?" data-csrf="GQcqNzRBBhwuVQcfOS1kBRwnFCcANgAAoVxov6alD/irVAV5ROwfkQ==" data-method="delete" data-to="/magnets/16" href="#" rel="nofollow">
                                            <span class="md md-delete"></span>
</a>

That looks correct. What are the event handlers registered on that element in the inspector?

I’m not seeing it trigger anything

Is anyone else having this issue, it’s pretty big and core to the app? And I can’t debug it no errors?

It seems that phoenix is correctly replacing the element, since it assigns the data-method, perhaps you have some JS lib that overrides the onclick handler for links?

I thought about that so I removed all JS libs and tried it, still not working

<%= link to: magnet_path(@conn, :delete, magnet), method: :delete, class: "btn btn-icon-toggle btn-refresh" do %>
                                            <span class="md md-delete"></span>
                                        <% end %>

Try without data confirm. Maybe something related to browser settings

I tried that and an I am getting an error

Unexpected string for import “phoenix_html”

So if I have the following

link to: magnet_path(@conn, :delete, magnet),

it’s still not calling the method delete in the controller but this does work link
to: magnet_path(@conn, :edit, magnet),

I think I might now what is causing the issue, can someone let me know if this is correct but the delete method shouldn’t it generate a form element outside the delete button

my main element does not have that

<div class="tools">
                            <div class="btn-group">
<a class="btn btn-icon-toggle btn-refresh" href="/magnets/21/edit">                                    <span class="md md-edit"></span>
</a>                                        <a class="btn btn-icon-toggle btn-refresh" data-confirm="Are you sure?" data-csrf="Qm8/eRAZEhwJOCM7FkZlXQxLZQ0INgAAwZJOdPyomkAQA4Q6DyVlRA==" data-method="delete" data-to="/magnets/21" href="#" rel="nofollow">
                                            <span class="md md-delete"></span>
</a>                            </div>
                        </div> 

Not sure why it’s not generated and how to fix that?

You can try that but i dont know if it works without crsf. Problem is looking about “phoenix_html” javascript package . Also you can try upgrade or reinstall “phoenix_html” from mix.exs

 <%= link to: magnet_path(@conn, :delete, magnet), data: [method: :delete], class: "btn btn-icon-toggle btn-refresh" do %>
                                                <span class="md md-delete"></span>
                                            <% end %>

Yea I tried the upgrade and install, the core issue is that “phoenix_html” is not getting loaded correctly which is wired as raw method works. I’m getting the undefined string on the import. The only thing I can think of is that something in my brunch config is not right but not seeing it.