From 79b4f0d03da920d97cf851592291aaac132f682a Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Mon, 3 Apr 2023 15:34:59 +0200 Subject: [PATCH] Add display of validation errors to TinyMCE [SCI-8246] --- app/controllers/my_modules_controller.rb | 2 +- app/javascript/packs/tiny_mce.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index f2ac67a1c..4549e9a13 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -348,7 +348,7 @@ class MyModulesController < ApplicationController render json: protocol, serializer: ProtocolSerializer, user: current_user rescue ActiveRecord::RecordInvalid - head :unprocessable_entity + render json: protocol.errors, status: :unprocessable_entity end def results diff --git a/app/javascript/packs/tiny_mce.js b/app/javascript/packs/tiny_mce.js index ed99c76cd..dbf1300a7 100644 --- a/app/javascript/packs/tiny_mce.js +++ b/app/javascript/packs/tiny_mce.js @@ -343,6 +343,8 @@ window.TinyMCE = (() => { editor.setProgressState(0); if (data.status === 403) { HelperModule.flashAlertMsg(I18n.t('general.no_permissions'), 'danger'); + } else if (data.status === 422) { + HelperModule.flashAlertMsg(data.responseJSON ? Object.values(data.responseJSON).join(', ') : I18n.t('errors.general'), 'danger'); } });