diff --git a/app/assets/javascripts/protocols/external_protocols_tab.js b/app/assets/javascripts/protocols/external_protocols_tab.js index 5fcac32bf..6d6612a1e 100644 --- a/app/assets/javascripts/protocols/external_protocols_tab.js +++ b/app/assets/javascripts/protocols/external_protocols_tab.js @@ -152,7 +152,7 @@ function showFormErrors(modal, errors) { Object.keys(errors.protocol).forEach(function(key) { var input = modal.find('#protocol_' + key); var msg; - msg = key.charAt(0).toUpperCase() + key.slice(1) + ': ' + errors.protocol[key].join(', '); + msg = errors.protocol[key].join(', '); if ((input.length > 0) && (errors.protocol[key].length > 0)) { input.closest('.form-group').children('span.help-block').html(msg); input.closest('.form-group').addClass('has-error'); @@ -195,7 +195,7 @@ function handleFormSubmit(modal) { HelperModule.flashAlertMsg(data.message, 'success'); }, error: function(data) { - showFormErrors(modal, data.responseJSON.errors); + showFormErrors(modal, data.responseJSON.validation_errors); }, complete: function() { animateSpinner(modal, false); diff --git a/app/assets/stylesheets/protocols/preview_modal.scss b/app/assets/stylesheets/protocols/preview_modal.scss index fadd62730..2613d169d 100644 --- a/app/assets/stylesheets/protocols/preview_modal.scss +++ b/app/assets/stylesheets/protocols/preview_modal.scss @@ -13,6 +13,14 @@ .ql-editor { min-height: initial; } + + .form-group.has-error { + color: $brand-danger; + + .sci-input-field { + border: 1px solid $brand-danger; + } + } } .general-error { diff --git a/app/controllers/external_protocols_controller.rb b/app/controllers/external_protocols_controller.rb index ed0e84439..7551c7989 100644 --- a/app/controllers/external_protocols_controller.rb +++ b/app/controllers/external_protocols_controller.rb @@ -19,7 +19,7 @@ class ExternalProtocolsController < ApplicationController page_id: service_call.protocols_list[:pagination][:current_page] } else - render json: { errors: service_call.errors }, status: 400 + render json: { errors: service_call.errors }, status: :bad_request end end @@ -43,7 +43,7 @@ class ExternalProtocolsController < ApplicationController rescue StandardError => e render json: { errors: [protocol_html_preview: e.message] - }, status: 400 + }, status: :bad_request end # GET build_online_sources_protocol @@ -74,7 +74,7 @@ class ExternalProtocolsController < ApplicationController validation_errors: { protocol: @protocol.errors.messages } } else - render json: { errors: service_call.errors }, status: 400 + render json: { errors: service_call.errors }, status: :bad_request end end @@ -95,7 +95,7 @@ class ExternalProtocolsController < ApplicationController render json: { protocol: service_call.protocol, message: message } else - render json: { errors: service_call.errors }, status: 400 + render json: { validation_errors: service_call.errors }, status: :bad_request end end diff --git a/app/services/protocol_importers/import_protocol_service.rb b/app/services/protocol_importers/import_protocol_service.rb index e3d832e8a..248ce6112 100644 --- a/app/services/protocol_importers/import_protocol_service.rb +++ b/app/services/protocol_importers/import_protocol_service.rb @@ -39,10 +39,12 @@ module ProtocolImporters TinyMceAsset.update_images(step_text, '[]', @user) - # 'Manually' create assets here. "Accept nasted attributes" won't work for assets + # 'Manually' create assets here. "Accept nested attributes" won't work for assets step.assets << AttachmentsBuilder.generate(step_params.deep_symbolize_keys, user: @user, team: @team) step end + rescue ActiveRecord::RecordInvalid => e + @errors[:protocol] = e.record.errors rescue StandardError => e @errors[:protocol] = e.message end