Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Forms, ImportFromJSONAction plugin] display form error inside form #7986

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@

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 @@
* @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 @@
}

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
Loading