2014-12-01 54 views
0

我正在使用disable_with,並且無法使按鈕文本更改保留(因爲它正在被disable_with功能覆蓋)。一旦我刪除, data: { disable_with: '...'按鈕將按預期更新。如何在Rails的遠程窗體`disable_with`功能完成後執行Javascript?

disable_with功能完成後有沒有辦法執行操作?

形式:

<%= form_for @user, html: {id: 'follow-form'}, remote: true do |f| %> 
    <%= button_tag id: 'follow-btn', data: { disable_with: '...' } do %> 
     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'); 
    } 
} 

回答

1

也許沒有disable_with和:

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

當AJAX請求成功:

$('#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}); 
    } 
}); 
相關問題