Rubytastic
Rubytastic

Reputation: 15501

suggestions to refactoring ajax form with submit button?

I have this popup that holds 2 buttons to decline and accept the problem is I'm trying to style the buttons and still also trigger a JS event to close the popup ( its a modal ajax popup) Problem is I have som lack of inspiration and ideas to get the below 3 elements combined together.

Some rails code:

  // ACCEPT FORM
  = form_tag(friend_path, :method => 'post', :remote => true) do
    = hidden_field_tag :user_id, current_user.id
    = submit_tag 'ACCEPT'

  // DECLINE FORM
  = form_tag(friend_path, :method => 'post', :remote => true) do
    = hidden_field_tag :user_id, current_user.id
    = submit_tag 'DECLINE'
    //fbmodal.close ()

Anyone some ideas how I can have the buttons

Upvotes: 1

Views: 283

Answers (1)

Ron
Ron

Reputation: 1166

Styleable buttons:

%button.btn#accept-button
  %i.icon-plus
  Accept

Your JS can then be something like:

$(document).ready(function() {
  $('#accept-button').click(function() {
    // replace this with your AJAX call
    $.get('/foo.json');
    // close the modal
    $('#your-modal-id').modal('hide');
    // and don't submit
    return false;
  });
});

Upvotes: 1

Related Questions