Skip to content

Commit

Permalink
[Forms, ImportFromJSONAction plugin] display form error inside form
Browse files Browse the repository at this point in the history
  • Loading branch information
johnriedel committed Jan 15, 2025
1 parent 5be103e commit 5530815
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/api/forms/components/FormRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
{{ row.name }}
</label>
<div class="c-form-row__state-indicator" :class="reqClass"></div>
<div v-if="row.control" ref="rowElement" class="c-form-row__controls"></div>
<div class="c-form-row__controls">
<div v-if="row.control" ref="rowElement"></div>
<div v-if="errorMessage" class="form-error">{{ errorMessage }}</div>
</div>
</div>
</template>

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 !== '';
Expand All @@ -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;

Check warning on line 132 in src/api/forms/components/FormRow.vue

View check run for this annotation

Codecov / codecov/patch

src/api/forms/components/FormRow.vue#L131-L132

Added lines #L131 - L132 were not covered by tests
});
}

return Boolean(valid);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/importFromJSONAction/ImportFromJSONAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -399,7 +399,7 @@ class ImportFromJSONAction {
}

if (!success) {
this.openmct.notifications.error(
fail(

Check warning on line 402 in src/plugins/importFromJSONAction/ImportFromJSONAction.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/importFromJSONAction/ImportFromJSONAction.js#L402

Added line #L402 was not covered by tests
'Invalid File: The selected file was either invalid JSON or was not formatted properly for import into Open MCT.'
);
}
Expand Down

0 comments on commit 5530815

Please sign in to comment.