Support the ongoing development of Laravel.io →
posted 10 years ago
Blade Forms
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

Man, I wasn't aware of the .prop() method. Thanks for pointing that out!

Last updated 2 years ago.
0

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);
});
Last updated 2 years ago.
0

Almost forgot an important part...

$('#deleteForm').attr('action', action);
Last updated 2 years ago.
0

You could better use data() instead of attr(), like: var data = $(this).data('id');, http://stackoverflow.com/a/7262427/444215

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

Yeah possibly a bit off the forum subject matter, but just wondering, what do you mean by "where" it stores the data?

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

Cool, thanks for the explanation!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Meowts meowts Joined 10 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.