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

phoenix
Tags: #<Tag:0x00007f039b2e1fa8>

#21

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


#22

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?


#23

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.


#24

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


#25

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


#26

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


#27

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


#28

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?


#29

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>

#30

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


#31

I’m not seeing it trigger anything


#32

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


#33

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?


#34

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


#35
<%= 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


#36

I tried that and an I am getting an error

Unexpected string for import “phoenix_html”


#37

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),


#38

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?


#39

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 %>

#40

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.