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)
}
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With