OpenCTI-Platform / opencti

Open Cyber Threat Intelligence Platform
https://opencti.io
Other
5.13k stars 813 forks source link

Form Validation Behavior Discrepancy #7401

Open ParamConstructor opened 1 week ago

ParamConstructor commented 1 week ago

Environment

  1. OS (where OpenCTI server runs): Mac OS
  2. OpenCTI version: OpenCTI 6.1.11
  3. OpenCTI client: Frontend UI
  4. Other environment details: N/A

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Configure Malware Analysis to require Maliciousness, Author, Markings, Product Version, and Submission Date (http://YOUR_OPENCTI_IP/dashboard/settings/customization/entity_types/Malware-Analysis)
  2. Navigate to (http://YOUR_OPENCTI_IP/dashboard/analyses/malware_analyses) and click on the FAB + to create a new Malware Analysis item.
  3. Fill in the Product Field.

Description / Discussion

Maliciousness, Author, and Markings are not flagged (they get flagged (by formik in the errors array) but only visually updated upon submission or if you manually interact with them). Formik does detect that they are not currently valid, but are only redrawn if they are "meta.touched" due to a change in AutoCompleteField that was submitted with the following historical issue (https://github.com/OpenCTI-Platform/opencti/issues/5741)

Should the form behavior be changed to be set to something like: validateOnChange={false} validateOnBlur={false}

Then, validation only occurs on fields you have touched or upon submission for these custom fields - is this the intended behavior? Or should the "meta.touched" be removed from line 84/85 of opencti-platform/opencti-front/src/components/AutocompleteField.jsx?

Expected Output

Maliciousness, Author, and Markings should be flagged and visually updated, since the form seems to be flagging required fields and doing an auto validation once the first field is interacted with.

image

Actual Output

Maliciousness, Author, and Markings are not flagged (they get flagged (by formik in the errors array) but only visually updated upon submission or if you manually interact with them). Formik does detect that they are not currently valid, but are only redrawn if they are "meta.touched" due to a change in AutoCompleteField that was submitted with the following historical issue (https://github.com/OpenCTI-Platform/opencti/issues/5741)

image

Additional information

This behavior was discovered while working this PR (https://github.com/OpenCTI-Platform/opencti/pull/6972) which actually adds "*"'s to the required fields so user can see what is required visually without error messages / ahead of time.

But submitting it as a Bug / Form Behavior Issue related to these custom type fields that rely on AutoCompleteField - to get a determination on the expect behavior.

Jipegien commented 1 week ago

Behavior of required fields (either native ones or configured in Settings) must be the same in forms.

lndrtrbn commented 5 days ago

Behavior of required fields (either native ones or configured in Settings) must be the same in forms.

@Jipegien yes it should be consistent, but what is the expected behavior we want?

Expected Output Maliciousness, Author, and Markings should be flagged and visually updated, since the form seems to be flagging required fields and doing an auto validation once the first field is interacted with.

In my opinion a field should be highlighted in red only if : it has been touched or the user has tried to submit the form (as describe in https://github.com/OpenCTI-Platform/opencti/issues/5741). Otherwise we are displaying errors on fields the user doesn't have manipulate yet and I feel this frustrating

ParamConstructor commented 5 days ago

@lndrtrbn - Discussed in a meeting on June 20th. There is a PR (https://github.com/OpenCTI-Platform/opencti/pull/7437) which will make behavior consistent to flag all fields red, since that is what all forms currently attempt to do. Then, there is a PR (https://github.com/OpenCTI-Platform/opencti/pull/6972) which will add "*"s (star to label) to denote field is required. Only fields touched and in error will immediately turn red (your preference above). All fields required fields with then only error on submission, if not touched by the user and required.

lndrtrbn commented 5 days ago

Ah okok we are on the same page then 😊 after the second PR we will have this behavior, thanks for the info!