From a104a5712b4b5074e72e67f78bc4cd634bee13ce Mon Sep 17 00:00:00 2001 From: "John C. Riedel" Date: Wed, 15 Jan 2025 02:59:02 +0000 Subject: [PATCH] [Forms, ImportFromJSONAction plugin] display form error inside form --- src/api/forms/components/FormRow.vue | 12 ++++++++++-- .../importFromJSONAction/ImportFromJSONAction.js | 6 ++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/api/forms/components/FormRow.vue b/src/api/forms/components/FormRow.vue index ce1c88e403d0..a1ccb510c782 100644 --- a/src/api/forms/components/FormRow.vue +++ b/src/api/forms/components/FormRow.vue @@ -26,7 +26,10 @@ {{ row.name }}
-
+
+
+
{{ errorMessage }}
+
@@ -54,6 +57,7 @@ export default { emits: ['on-change'], data() { return { + errorMessage: null, formControl: this.openmct.forms.getFormControl(this.row.control), valid: undefined, visited: false @@ -105,6 +109,7 @@ export default { this.$emit('on-change', data); }, validateRow(data) { + this.errorMessage = null; let valid = true; if (this.row.required) { valid = data.value !== undefined && data.value !== null && data.value !== ''; @@ -122,7 +127,10 @@ export default { const validate = data.model.validate; if (valid && validate) { - valid = validate(data); + valid = validate(data, (errorMessage = null) => { + this.errorMessage = errorMessage; + return false; + }); } return Boolean(valid); diff --git a/src/plugins/importFromJSONAction/ImportFromJSONAction.js b/src/plugins/importFromJSONAction/ImportFromJSONAction.js index 77fa1dfda910..3ffcf8d2351b 100644 --- a/src/plugins/importFromJSONAction/ImportFromJSONAction.js +++ b/src/plugins/importFromJSONAction/ImportFromJSONAction.js @@ -383,7 +383,7 @@ class ImportFromJSONAction { * @param {Object} data * @returns {boolean} */ - _validateJSON(data) { + _validateJSON(data, fail) { const value = data.value; const objectTree = value && value.body; let json; @@ -399,9 +399,7 @@ class ImportFromJSONAction { } if (!success) { - this.openmct.notifications.error( - 'Invalid File: The selected file was either invalid JSON or was not formatted properly for import into Open MCT.' - ); + fail('Invalid File: The selected file was either invalid JSON or was not formatted properly for import into Open MCT.'); } return success;