August 16th, 2011 | by Gazer |
Template
<%= form_for @object, :remote => true do |form| %>
<%= submit_tag 'Enviar', :class => 'submit' %>
<% end %>
Javascript
$(function () {
var loading = $('<img />').attr('src', '/images/loadingAnimation.gif').addClass('submit');
$('form').bind('ajax:complete', function(evt, data, status, xhr) {
// Mostrar el boton y sacar la imagen de loading
$(this).find('.submit').show();
$(loading).detach();
$(this).find('textarea').val('');
$(this).find('input').val('');
// Cualquier otra regla de limpieza que se quiera aplicar :)
}).bind('ajax:beforeSend', function () {
var valid = true; // Poner logica de validacion;
if (valid) {
// Ocultad el boton y mostrar la imagen de loading en su lugar
$(this).find('.submit').hide();
$(this).find('.submit').before(loading);
}
return valid;
});
});
Authored by Gazer
Just Me. If you have something to say, please leave a comment somewhere :)