You could always do a quick JavaScript fix for this
{{ Form::open(['method'=>'post', 'id' => 'myform', 'route'=>['user_delete_service', '#DUMMYID#']]) }}
and in the JS code (didn't test this, so might not be 100% accurate :) ):
var theform = $('#myform');
var theimage = $('#myimage');
theform.prop('action) = theform.prop('action').replace('#DUMMYID#', theimage.prop('data-id'));
theform.submit();
Maybe not the best way to go about it, but should work
Man, I wasn't aware of the .prop() method. Thanks for pointing that out!
Thanks a million, that approach helped a lot.
Seems pretty obvious now lol.
$('.delete_button').click(function(){
var action = $('#deleteForm').attr('action');
var data = $(this).attr('data-id');
action = action.replace('XXX', data);
});
Almost forgot an important part...
$('#deleteForm').attr('action', action);
You could better use data()
instead of attr()
, like: var data = $(this).data('id');
,
http://stackoverflow.com/a/7262427/444215
I think that prop() is recommended to set standard html attributes over attr(). data() stores data to en element, currently in an attribute, but the jQuery docs says it can not specify where it stores the data, just that you can store and retrieve it, so I wouldn't rely on data() for reading/changing attributes for future compatibility. Or maybe I'm just paranoid :)
Although this is jQuery discussions, so I'll leave that for another forum
Yeah possibly a bit off the forum subject matter, but just wondering, what do you mean by "where" it stores the data?
Yeah possibly a bit off the forum subject matter, but just wondering, what do you mean by "where" it stores the data?
Well, jQuery says the data() method stores and retrieves data, so that it can be used to save data and retrieve it at a later time. The method of which the data is stored should not be taken into account though, and may change in the future. Right now the data is added as a tag on the element, but in the next jQuery release they might have changed it to be stored in a cookie, or the visitors localStorage, or something similar.
This is just something I read somewhere in a jQuery discussion thread, that using data() to read tags that you didn't set with data() is not recommended for future compatibility. But that being said, I highly doubt that this will change, so it feels pretty safe to use either way :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community