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

oneOf validator for polymorphic data #91

Closed
maxime1992 opened this issue Aug 20, 2019 · 3 comments · May be fixed by #94
Closed

oneOf validator for polymorphic data #91

maxime1992 opened this issue Aug 20, 2019 · 3 comments · May be fixed by #94
Assignees
Labels
effort-2: hours Will only take a few hours to fix/create scope: lib Anything related to the library itself state: has PR A PR is available for that issue type: feature This is a new feature

Comments

@maxime1992
Copy link
Contributor

When dealing with polymorphic data and using the remap functions it'd be nice to have a oneOf validator. It'd take as argument keys of the formGroup so it'd also be type safe.

Example here https://github.com/cloudnc/ngx-sub-form/blob/6ecdb2017e/src/app/main/listing/listing-form/vehicle-listing/vehicle-product.component.ts#L24-L25

And it could look like the following:

public getFormGroupControlOptions(): FormGroupOptions<YourPolymorphicForm> {
  return {
    validators: [NgxSubFormValidators.OneOf('prop1', 'prop2', 'prop3')],
  };
}
@maxime1992 maxime1992 added scope: lib Anything related to the library itself type: RFC/discussion/question This issue is about RFC, discussion or a question effort-1: minutes Will only take a few minutes to fix/create type: feature This is a new feature labels Aug 20, 2019
@maxime1992 maxime1992 self-assigned this Aug 26, 2019
maxime1992 added a commit that referenced this issue Aug 29, 2019
@maxime1992 maxime1992 added effort-2: hours Will only take a few hours to fix/create state: has PR A PR is available for that issue and removed effort-1: minutes Will only take a few minutes to fix/create type: RFC/discussion/question This issue is about RFC, discussion or a question labels Aug 29, 2019
@andreElrico
Copy link

andreElrico commented Sep 3, 2019

Im currently developing a feature to deal with polymorphic data in a much simpler fashion.
For me its feels a bit overkill to make 3 subforms when you have for e.g. 3 animals.

                        animal
              /           |           \
              dogForm  mouseForm  catForm

It would make sense to have 4 forms when the subforms are "large and complex". I will let you know on my progress.
The basic idea is to have only ONE full-form and then use ng-switch like you do and disable all not used formControls.

@maxime1992
Copy link
Contributor Author

The validator wouldn't be aware whether you implement the 3 sub forms in the same component or if you break them down. The validator would be here only to guarantee that the form would be in valid state if exactly 1 value of the 3 possible ones is defined.

@maxime1992
Copy link
Contributor Author

Validators are not really supposed to be part of ngx-sub-form. I mixed things up here because we do need this in our own app so I'm just going to close this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort-2: hours Will only take a few hours to fix/create scope: lib Anything related to the library itself state: has PR A PR is available for that issue type: feature This is a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants