0

I am using disable_with, and cannot get the button text change to persist (because it is being overwritten by the disable_with functionality). As soon as I remove , data: { disable_with: '...' the buttons are updated as expected.

Is there a way to perform actions after the disable_with functionality has completed?

form:

<%= 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 Answer 1

1

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});
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.