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

[Form lib] Error when validating the form with non blocking validations #102338

Closed
sebelga opened this issue Jun 16, 2021 · 3 comments
Closed

[Form lib] Error when validating the form with non blocking validations #102338

sebelga opened this issue Jun 16, 2021 · 3 comments
Labels
bug Fixes for quality problems that affect the customer experience Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more

Comments

@sebelga
Copy link
Contributor

sebelga commented Jun 16, 2021

Non blocking validation

The form lib allows consumer to declared "non blocking" validations by setting isBlocking: false to a validator.

Let's imagine we have a field with an array of "Tags". In this case, we allow an empty array (no tags needs to be provided) but we want to have a validation when adding a tag to the array (for example: the tag cannot contain the $ character otherwise we won't add it to the array and instead we will show the validation message to the user explaining why the tag could not be added.)

The field, which is the array of tags, is still valid. Simply, no items have been added yet.

The issue

We have an issue in the form lib when validating the form with non blocking validations. Calling form.validate() will call all the validations, including the non blocking ones and thus will block submitting the form.

I've debugged this with @machadoum and the fix might be simple and we might simply need to change the validate() function of the use_field.ts file

const validate: FieldHook<T, I>['validate'] = useCallback(
  (validationData = {}) => {
    const {
      formData = __getFormData$().value,
      value: valueToValidate = value,
      validationType, // before
      validationType = VALIDATION_TYPES.FIELD, // after
    } = validationData;

  ...
}

As this is a very sensitive area of the form lib I want to make sure I haven't overlooked something and obviously add tests around that scenario.

This issue was found by Pablo here: #101756 (comment)

@sebelga sebelga added the bug Fixes for quality problems that affect the customer experience label Jun 16, 2021
@botelastic botelastic bot added the needs-team Issues missing a team label label Jun 16, 2021
@sebelga sebelga added the Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more label Jun 16, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-management (Team:Stack Management)

@botelastic botelastic bot removed the needs-team Issues missing a team label label Jun 16, 2021
machadoum added a commit to machadoum/kibana that referenced this issue Jul 12, 2021
machadoum added a commit that referenced this issue Jul 13, 2021
…3629)

* Fix error when validating the form with non blocking validations

issue: #102338

* Add a flag to only validate blocking validation when validating the form

* Refactor bypass validation

Co-authored-by: Sébastien Loix <sabee77@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
machadoum added a commit to machadoum/kibana that referenced this issue Jul 13, 2021
…stic#103629)

* Fix error when validating the form with non blocking validations

issue: elastic#102338

* Add a flag to only validate blocking validation when validating the form

* Refactor bypass validation

Co-authored-by: Sébastien Loix <sabee77@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
machadoum added a commit that referenced this issue Jul 13, 2021
…3629) (#105478)

* Fix error when validating the form with non blocking validations

issue: #102338

* Add a flag to only validate blocking validation when validating the form

* Refactor bypass validation

Co-authored-by: Sébastien Loix <sabee77@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Sébastien Loix <sabee77@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@cjcenizal
Copy link
Contributor

Seb has this been fixed by #103629?

@sebelga
Copy link
Contributor Author

sebelga commented Jul 26, 2021

Yes @cjcenizal thanks for the ping. Closing as it has been fixed in #103629

@sebelga sebelga closed this as completed Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more
Projects
None yet
Development

No branches or pull requests

3 participants