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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose tree-shakable validator functions via public API #41257

Open
penfold opened this issue Mar 18, 2021 · 7 comments
Open

Expose tree-shakable validator functions via public API #41257

penfold opened this issue Mar 18, 2021 · 7 comments
Assignees
Labels
area: forms feature: in backlog Feature request for which voting has completed and is now in the backlog feature Issue that requests a new feature
Milestone

Comments

@penfold
Copy link

penfold commented Mar 18, 2021

馃悶 bug report

Affected Package

@angular/forms

Is this a regression?

No

Description

Following #41189 in NG 11.2.6. I was expecting to be able to use the new validator functions directly.

e.g. use requiredValidator instead of Validators.required.

After a bit of digging it would seem that they are marked for internal use (?).

In the forms.d.ts, I expected 傻angular_packages_forms_forms_bb to be requiredValidator.

/**
 * @description
 * Provider which adds `RequiredValidator` to the `NG_VALIDATORS` multi-provider list.
 */
export declare const 傻angular_packages_forms_forms_bb: StaticProvider;

/**
 * @description
 * Provider which adds `CheckboxRequiredValidator` to the `NG_VALIDATORS` multi-provider list.
 */
export declare const 傻angular_packages_forms_forms_bc: StaticProvider;

/**
 * @description
 * Provider which adds `EmailValidator` to the `NG_VALIDATORS` multi-provider list.
 */
export declare const 傻angular_packages_forms_forms_bd: any;

/**
 * @description
 * Provider which adds `MinLengthValidator` to the `NG_VALIDATORS` multi-provider list.
 */
export declare const 傻angular_packages_forms_forms_be: any;

/**
 * @description
 * Provider which adds `MaxLengthValidator` to the `NG_VALIDATORS` multi-provider list.
 */
export declare const 傻angular_packages_forms_forms_bf: any;

馃敩 Minimal Reproduction

N/A

馃敟 Exception or Error

N/A

馃實 Your Environment

Angular Version:
11.2.6

@petebacondarwin petebacondarwin added area: forms feature Issue that requests a new feature labels Mar 18, 2021
@ngbot ngbot bot modified the milestone: Backlog Mar 18, 2021
@penfold
Copy link
Author

penfold commented Mar 18, 2021

This is when using Reactive form validation as documented: https://angular.io/guide/reactive-forms#validating-form-input

@penfold
Copy link
Author

penfold commented Mar 18, 2021

Do the method summary comments just need @publicapi to be added?

@JoostK
Copy link
Member

JoostK commented Mar 18, 2021

The changes in #41189 were to allow internal usages of individual validators to not also pull in all of Validators. It was not about extending the public API to allow external packages to do the same. Extending API could not have been done in a patch release and it would require a strategy for possibly deprecating the static methods on Validators.

@penfold
Copy link
Author

penfold commented Mar 18, 2021

@JoostK Thank you for your explanation. This release would only give a bundle size benefit to people using Template forms. It would be great if it can be extended to my use case using Reactive forms.

On a side note, it's good to see forms in general gettings some attention from the NG team. Thank you.

@AndrewKushnir
Copy link
Contributor

@penfold thanks for creating this ticket. As Joost mentioned above, the goal of #41189 was to perform internal refactoring to make validators code tree-shakable without changing the API surface.

We'll consider adding these standalone validator functions to the public API, but that would require additional discussions/decisions like deprecating Validators class (or at least stop recommending it in docs and use tree-shakable functions instead) and potentially creating a new entry-point in @angular/forms for more ergonomic (and similar to what we have now) usage like this:

import * as Validators from '@angular/forms/validators';
...
const control = new FormControl('', Validators.required);

We'll keep this ticket updated once there is any new information available.

@AndrewKushnir AndrewKushnir changed the title Non-static validator functions not available in forms.d.ts Expose tree-shakable validator functions in public API Mar 23, 2021
@AndrewKushnir AndrewKushnir changed the title Expose tree-shakable validator functions in public API Expose tree-shakable validator functions via public API Mar 23, 2021
@splincode
Copy link
Contributor

@AndrewKushnir great idea (migration with schematics, if needed)

import * as Validators from '@angular/forms/validators';
...
const control = new FormControl('', Validators.required);

@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Jun 4, 2021
@angular-robot
Copy link
Contributor

angular-robot bot commented Jun 4, 2021

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

@AndrewKushnir AndrewKushnir added feature: in backlog Feature request for which voting has completed and is now in the backlog and removed feature: votes required Feature request which is currently still in the voting phase labels Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: forms feature: in backlog Feature request for which voting has completed and is now in the backlog feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

5 participants