Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete link not working phoenix

I've used Phoenix's built in gen.HTML to generate a simple view but it's not working

<%= link "Delete", to: event_path(@conn, :delete, event), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %>

And on the page it looks like it suppose to but it just append # to address

Generated structure:

<form action="/event/1" class="link" method="post">
   <input name="_method" type="hidden" value="delete">
   <input name="_csrf_token" type="hidden" value="BwUSGQcDO1MwPzw0HBgqLnshHn8HNgAAnCTjuMt0viFshobX4XM/dQ==">
   <a class="btn btn-danger btn-xs" data-confirm="Are you sure?" data-submit="parent" href="#">Delete</a>
</form>

Am i missing a js import of sort? I can also this being downloaded by the browser:

//This is being downloaded as phoenix_html.js
// Although ^=parent is not technically correct,
// we need to use it in order to get IE8 support.
var elements = document.querySelectorAll('[data-submit^=parent]')
var len = elements.length

for (var i=0; i<len; ++i) {
  elements[i].addEventListener('click', function(event){
    var message = this.getAttribute("data-confirm")
    if(message === null || confirm(message)){
      this.parentNode.submit()
    };
    event.preventDefault()
    return false
  }, false)
}
like image 733
MJay Avatar asked Dec 14 '15 17:12

MJay


2 Answers

For anyone else hitting this I had a completely different problem that manifested itself in the same way, will drop this here in case it helps:

It turns out I accidentally deleted import "phoenix_html" from the app.js file mistaking it for being part of the generated boilerplate, adding it back fixed my issue.

like image 187
Howard Beard-Marlowe Avatar answered Sep 19 '22 09:09

Howard Beard-Marlowe


While not the particular solution to OP's issue, this error can also arise if you place

<script src="<%= static_path(@conn, "/js/app.js") %>"></script>

in the the wrong place in app.html.eex. (For example inside <head> instead of at the end of the body)

like image 20
David Kuhta Avatar answered Sep 22 '22 09:09

David Kuhta