Skip to content

Commit

Permalink
Merge pull request #1 from DATA-DOG/feature/js-form-in-content
Browse files Browse the repository at this point in the history
js-form not in modals
  • Loading branch information
ValdasK committed Nov 4, 2015
2 parents 1e3faa2 + 53477da commit e946e7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/modal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,29 @@
}

function onJsFormSubmit(event) {
var form = $(this);
var formData = new FormData(this);

$(document).trigger('bsmodal.js-form.submitted', [$(this), formData]);

$.ajax({
url: $(this).attr("action"),
type: $(this).attr("method"),
url: form.attr("action"),
type: form.attr("method"),
data: formData,
processData: false,
contentType: false,
success: function(data, status, xhr) {
$(document).trigger('bsmodal.js-form.success', [data, status, xhr]);
$(document).trigger('bsmodal.js-form.success', [data, status, xhr, form]);
},
complete: function() {
$(document).trigger('bsmodal.js-form.completed');
$(document).trigger('bsmodal.js-form.completed', [form]);
}
});

event.preventDefault();
}

function onJsFormSuccess(event, data, status, xhr) {
function onJsFormSuccess(event, data, status, xhr, form) {
if (xhr.status == 201) {
modal.modal('hide');

Expand All @@ -96,7 +97,13 @@
window.location.reload();
}
} else {
displayContent(data);
if (modal.hasClass('in') && modal.find('.js-form')) {
displayContent(data);
} else if (form.attr('id')) {
form.html($(data).find('#' + form.attr('id')));
} else {
console.debug(".js-form must have an id attribute or be in modal window")
}
}
}

Expand Down

0 comments on commit e946e7f

Please sign in to comment.