How to execute Javascript after Rails' remote form `disable_with` functionality has completed? -


i using disable_with, , cannot button text change persist (because being overwritten disable_with functionality). remove , data: { disable_with: '...' buttons updated expected.

is there way perform actions after disable_with functionality has completed?

form:

<%= form_for @user, html: {id: 'follow-form'}, remote: true |f| %>     <%= button_tag id: 'follow-btn', data: { disable_with: '...' } %>         follow     <% end %> <% end %> 

js:

$('#follow-form').on('ajax:success',function(data, status, xhr){     if (status.action == 'follow') {         $('#follow-btn').text('unfollow');     } else {         $('#follow-btn').text('follow');     } } 

maybe without disable_with and:

$('#follow-form').on('ajax:send',function(data, status, xhr){     $('#follow-btn').text('please wait...').attr({disabled: true}); }); 

and when ajax request succeeds:

$('#follow-form').on('ajax:success',function(data, status, xhr){     if (status.action == 'follow') {         $('#follow-btn').text('unfollow').attr({disabled: false});     } else {         $('#follow-btn').text('follow').attr({disabled: false});     } }); 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -