Skip to content

[WIP] Enable conditional validation of fields in DDF forms #7312

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

Closed

Conversation

skateman
Copy link
Member

This is the implementation of the idea proposed here, basically allowing to use the same condition syntax that is already available when displaying/hiding fields. It is wrapping each validator in the validatorMapper with the condition parsing that has been exposed for external usage.

[
  {
    component: componentTypes.SELECT,
    name: "country",
    label: "Country",
    options: [
      { value: "us", label: "United States" },
      { value: "xx", label: "Other" },
    ],
  },
  {
    component: componentTypes.TEXT_FIELD,
    name: "state",
    label: "State/province",
    validate: [
      {
        type: validatorTypes.REQUIRED,
        condition: {
          when: "country",
          is: "us"
        }
      }
    ],
  }
]

This would (partially) solve an issue in the IBM Cloud provider form where some fields would be not required if a dropdown is set to the right value. However, it doesn't deal with the visibility of * and some other aspects, so I am also considering to create a specialized wrapper component (with a fields attribute similarly to the validator) that would solve all the issues by altering the schema of the fields beneath.

Even if I go with the other solution, this might be useful in other areas and so I'm leaving it here for discussion as a draft.

@skateman skateman force-pushed the ddf-conditional-validation branch from dcc68db to 736a8be Compare September 17, 2020 13:23
@miq-bot
Copy link
Member

miq-bot commented Sep 17, 2020

Checked commit skateman@736a8be with ruby 2.6.3, rubocop 0.69.0, haml-lint 0.28.0, and yamllint
0 files checked, 0 offenses detected
Everything looks fine. 👍

@skateman skateman changed the title Enable conditional validation of fields in DDF forms [WIP] Enable conditional validation of fields in DDF forms Sep 22, 2020
@skateman skateman marked this pull request as ready for review September 22, 2020 08:53
@miq-bot miq-bot added the wip label Sep 22, 2020
@miq-bot
Copy link
Member

miq-bot commented Oct 22, 2020

This pull request is not mergeable. Please rebase and repush.

@skateman skateman closed this Feb 18, 2021
@skateman skateman deleted the ddf-conditional-validation branch February 18, 2021 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants