Adam Templeton
Adam Templeton

Reputation: 4617

Rails: Disabling an image_submit_tag

I have a button on my signup form, like such:

<%= image_submit_tag('/assets/atmosphere_forward.png', :class => "signup_submit_button")%>

When the user clicks it, there's a delay of a few seconds while the form is being processed. How can I change the image of submit button while this is occurring (similar to using :disable_with with other tags)?

Or, alternatively, how can I add a field to my form that only appears when the form is processing (which could contain "Please Wait" or something similar)?

Upvotes: 0

Views: 358

Answers (1)

matsko
matsko

Reputation: 22223

I don't think that the Rails UJS tools are enough to change the state of an input field, add/remove a class or show and hide properties. You will have to use JavaScript.

form = $('#your_form');
form.submit(function(event) {
  //change the button
  var btn = form.find('input[type="submit"]');
  btn.image = '...';

  //setup the please wait message
  var message = $('<div class="please-wait">Please Wait...</div>');
  form.append(message);
});

I do suggest for the form button you use CSS and then just change the class within your submit event.

Upvotes: 1

Related Questions