Skip to content

Commit dea63f4

Browse files
committed
Fix remote form to work with rails-ujs
Refs. #3390
1 parent b385d4d commit dea63f4

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

app/assets/javascripts/rails_admin/ra.remote-form.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,22 @@
7272
cancelButtonText = dialog.find(":submit[name=_continue]").html();
7373
dialog.find('.form-actions').remove();
7474

75-
form.attr("data-remote", true);
75+
form.attr("data-remote", true).attr("data-type", "json");
7676
dialog.find('.modal-header-title').text(form.data('title'));
7777
dialog.find('.cancel-action').unbind().click(function(){
7878
dialog.modal('hide');
7979
return false;
8080
}).html(cancelButtonText);
8181

8282
dialog.find('.save-action').unbind().click(function(){
83-
form.submit();
83+
window.Rails.fire(form[0], 'submit');
8484
return false;
8585
}).html(saveButtonText);
8686

8787
$(document).trigger('rails_admin.dom_ready', [form])
8888

89-
form.bind("ajax:complete", function(xhr, data, status) {
89+
form.bind("ajax:complete", function(event) {
90+
var data = event.detail[0], status = event.detail[1];
9091
if (status == 'error') {
9192
dialog.find('.modal-body').html(data.responseText);
9293
widget._bindFormEvents();

lib/rails_admin/config/actions/edit.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Edit < RailsAdmin::Config::Actions::Base
3131
@auditing_adapter&.update_object(@object, @abstract_model, _current_user, changes)
3232
respond_to do |format|
3333
format.html { redirect_to_on_success }
34-
format.js { render json: {id: @object.id.to_s, label: @model_config.with(object: @object).object_label} }
34+
format.json { render json: {id: @object.id.to_s, label: @model_config.with(object: @object).object_label} }
3535
end
3636
else
3737
handle_save_error :edit

lib/rails_admin/config/actions/new.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class New < RailsAdmin::Config::Actions::Base
4242
@auditing_adapter&.create_object(@object, @abstract_model, _current_user)
4343
respond_to do |format|
4444
format.html { redirect_to_on_success }
45-
format.js { render json: {id: @object.id.to_s, label: @model_config.with(object: @object).object_label} }
45+
format.json { render json: {id: @object.id.to_s, label: @model_config.with(object: @object).object_label} }
4646
end
4747
else
4848
handle_save_error

0 commit comments

Comments
 (0)