Created
January 8, 2021 00:58
-
-
Save pedryvo/ae681f50b8be1cc7c5ec31871a4fedfc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// require materialize.css | |
$(document).on('turbolinks:load', function() { | |
$('.update_form .regular').on('focusout', event => $('.update_form').trigger('submit')); | |
$('.update_form').on('submit', e => { | |
$.ajax(e.target.action, { | |
type: 'PUT', | |
dataType: 'json', | |
data: $(".update_form").serialize(), | |
success(data, text, jqXHR) { | |
return M.toast({html: 'Form updated', displayLength: 4000, classes: 'green darken-1' }); | |
}, | |
error(jqXHR, textStatus, errorThrown) { | |
return M.toast({html: 'Form not updated', displayLength: 4000, classes: 'red darken-1' }); | |
} | |
} | |
); | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment