Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Little JavaScript helpers for a Laravel app.
{{ Form::open(['data-remote', 'data-remote-success-message' => 'I have now done the thing.']) }}
{{ Form::text('name') }}
{{ Form::submit('Submit', ['data-confirm' => 'Are you sure?']) }}
{{ Form::close() }}
(function() {
var submitLaravelRequest = function(e) {
var form = $(this);
var method = form.find('input[name="_method"]').val() || 'POST';
var url = form.prop('action');
type: method,
url: url,
data: form.serialize(),
success: function() {
var message ='remote-success-message');
if (message) {
var confirmAction = function(e) {
var input = $(this);
input.prop('disabled', 'disabled');
// Or, much better, use a dedicated modal.
if ( ! confirm('confirm'))) {
// And bind functions to user events.
$('form[data-remote]').on('submit', submitLaravelRequest);
$('input[data-confirm], button[data-confirm]').on('click', confirmAction);

This comment has been minimized.

Copy link
Owner Author

laracasts commented Aug 9, 2014

Or, if you want to take this a step further...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.