From dfa621d0bc0e5ddf040c58f04b26560ef142a53c Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Sun, 12 Apr 2020 16:50:17 +0200 Subject: [PATCH] Add submission response to event details in tinyforms.js This makes the submitted data more easily accessible --- app/controllers/submissions_controller.rb | 2 +- app/javascript/tinyforms.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 518a3eb..9d801af 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -14,7 +14,7 @@ class SubmissionsController < ApplicationController respond_to do |format| if @submission.save format.html { redirect_to(@form.thank_you_url) if @form.thank_you_url.present? } - format.json { render(json: { success: true, data: @submission.data }) } + format.json { render(json: { success: true, submission: @submission.data }) } else format.html { redirect_to(@form.thank_you_url) if @form.thank_you_url.present? } format.json { render(json: { error: @submission.errors }, status: 422) } diff --git a/app/javascript/tinyforms.js b/app/javascript/tinyforms.js index bcb446d..c1e242c 100644 --- a/app/javascript/tinyforms.js +++ b/app/javascript/tinyforms.js @@ -38,10 +38,10 @@ window.tinyforms = { e.preventDefault(); return tinyforms.submitForm(this) .then((response) => { - this.dispatchEvent(new CustomEvent('tinyforms:submitted', {detail: { response: response }})); + this.dispatchEvent(new CustomEvent('tinyforms:submitted', {detail: { submission: response.submission, response: response }})); }) .catch((response) => { - this.dispatchEvent(new CustomEvent('tinyforms:error', {detail: { response: response }})); + this.dispatchEvent(new CustomEvent('tinyforms:error', {detail: { submission: response.submission, response: response }})); }); } };