After extensive googling, I have been unable to find my mistake. As a beginner with JS, this may be an easy fix for someone with more experience. Working with Rails 4.
I am working on a modal that contains a form and I want to perform certain actions after a successful (or unsuccessful) ajax call, such as closing the modal.
Modal structure (works fine for editing):
.modal.fade{ id: attribute.id, role: 'dialog', tabindex:'-1' }
.modal-dialog{ role: 'document'}
.modal-content
.modal-header
%button{ type: 'button', class: 'close', 'data-dismiss' => "modal" }
%span ×
%h4.modal-title= attribute.name
= form_for attribute, remote: true, html: { class: 'form-inline', id: 'edit_form' } do |f|
.modal-body
.form-group
= f.label :name, 'Name', class: 'form-label', style: 'width: 150px'
= f.text_field :name, class: 'form-control', style: 'width:200px;margin-right: 35px'
.modal-footer
%button{ type: "button", class: "btn btn-default pull-left", 'data-dismiss' => "modal" }
Close
= f.submit 'Create', class: 'btn btn-primary pull-right'
My not-so-impressive JS file:
$(document).ready( function($) {
console.log('ready'); # visible in console
$('#edit_form').bind("ajax:success", function() {
console.log('great success') # *not* visible in console.
});
});
Controller snippet (interesting fact: Modal triggered in view from different controller than intended one):
respond_to do |format|
format.js {}
end
I aim to handle the error and success callbacks independently and work with them accordingly (currently investigating this myself). What could be the issue here?
Your assistance is greatly appreciated!