openmct icon indicating copy to clipboard operation
openmct copied to clipboard

Error messages should appear with form controls

Open ghost opened this issue 10 months ago • 2 comments

Is your feature request related to a problem? Please describe. I recommend displaying form errors in form pop-up modals (ie: Create Wizard). A good example of a problem I see is with the "Import From JSON" plugin action functionality. Here are some details.

When I click "Import From JSON" in the action menu, a pop-up modal appears with a file-input control that expects a file with JSON contents.

Image

Image

If I choose a file that fails validation, a red X appears next to the form with no information about what the error is, why validation failed, or what I need to fix.

Image

Instead, I have to close the pop-up modal and look at the top of the screen to read the notification error.

Image

Then I have to re-open the pop-up modal and try again. As you can imagine, this is not ideal especially if there are a number of form controls that need to be populated in the pop-up modal.

Describe the solution you'd like I think it makes more sense for every form control to have an associated error message that would appear immediately under the control. That way, the validation feedback is immediate without having to close, reopen, and repopulate the pop-up modal.

Image

As far as implementation is concerned, a plugin control's validation function will have a second optional parameter, "fail", which is a function that takes one argument, an error message. So if validation fails, the validation function would simply contain one of the following code options:

fail('This file must contain JSON.'); return false; ....or.... return fail('This file must contain JSON.');

For example:

Image

Describe alternatives you've considered

Additional context

ghost avatar Jan 15 '25 02:01 ghost

Code updates complete. Opening PR soon.....

ghost avatar Jan 15 '25 02:01 ghost

Associated PR: https://github.com/nasa/openmct/pull/7986

ghost avatar Jan 15 '25 03:01 ghost