Skip to content

Commit

Permalink
Fix remote form to work with rails-ujs
Browse files Browse the repository at this point in the history
Refs. #3390
  • Loading branch information
mshibuya committed Sep 21, 2021
1 parent b385d4d commit dea63f4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/rails_admin/ra.remote-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,22 @@
cancelButtonText = dialog.find(":submit[name=_continue]").html();
dialog.find('.form-actions').remove();

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

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

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

form.bind("ajax:complete", function(xhr, data, status) {
form.bind("ajax:complete", function(event) {
var data = event.detail[0], status = event.detail[1];
if (status == 'error') {
dialog.find('.modal-body').html(data.responseText);
widget._bindFormEvents();
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/actions/edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Edit < RailsAdmin::Config::Actions::Base
@auditing_adapter&.update_object(@object, @abstract_model, _current_user, changes)
respond_to do |format|
format.html { redirect_to_on_success }
format.js { render json: {id: @object.id.to_s, label: @model_config.with(object: @object).object_label} }
format.json { render json: {id: @object.id.to_s, label: @model_config.with(object: @object).object_label} }
end
else
handle_save_error :edit
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/actions/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class New < RailsAdmin::Config::Actions::Base
@auditing_adapter&.create_object(@object, @abstract_model, _current_user)
respond_to do |format|
format.html { redirect_to_on_success }
format.js { render json: {id: @object.id.to_s, label: @model_config.with(object: @object).object_label} }
format.json { render json: {id: @object.id.to_s, label: @model_config.with(object: @object).object_label} }
end
else
handle_save_error
Expand Down

0 comments on commit dea63f4

Please sign in to comment.