Commit graph

368 commits

Author SHA1 Message Date
Paul Gschwendtner
c46d533b22 build: switch devmode output to es2015 (#44505)
To make our test output i.e. devmode output more aligned
with what we produce in the NPM packages, or to be more
aligned with what Angular applications will usually consume,
the devmode output is switched from ES5 to ES2015.

Additionally various tsconfigs (outside of Bazel) have been
updated to match with the other parts of the build. The rules
are:

ES2015 for test configurations, ES2020 for actual code that will
end up being shipped (this includes the IDE-only tsconfigs).

PR Close #44505
2022-01-05 23:20:20 +00:00
Andrew Kushnir
8388151f4d refactor(forms): make validators code compatible with property renaming (#44500)
This commit refactors the code of the base validators class to make it compatible with the property renaming optimization. Currently the code makes an assumption that the field with a specified name (defined as a string) can be found on an object, but with property renaming optimization this is not correct.

PR Close #44500
2022-01-05 18:43:36 +00:00
Dylan Hunn
5ae1030462 feat(forms): Add an unused symbol AnyForUntypedForms. (#44467)
This symbol will support the typed forms migration in google3. The docs will be updated once the migration begins.

Pertains to #13721.

PR Close #44467
2022-01-04 12:18:26 -08:00
Dylan Hunn
f7aa937cac fix(forms): Make some minor fixups for forward-compatibility with typed forms. (#44540)
Make the following fixes:
* When submitting the entire migration in a disabled state, I commented out more code than strictly required
* Responding to some final review comments caused two conditions to become flipped
* Always use explicit checks instead of boolean corecion
* Fix one missed any cast in a test case

PR Close #44540
2022-01-04 12:10:56 -08:00
Dylan Hunn
6a0dadf46f fix(forms): _reduceValue arrow function now has correct types. (#44483)
I previously strengthened some weak types in #44370. One of these fixes exposed an incorrect call into `_reduceChildren` from `_reduceValue`. This was caught in google3 by a caller who was extending `FormGroup` and overriding these methods.

Special thanks to Bart G for catching this issue and suggesting a fix.

PR Close #44483
2021-12-15 12:27:06 -05:00
Dylan Hunn
72092ebd26 feat(forms): Allow a FormControl to use initial value as default. (#44434)
Allow a FormControl to be reset to its initial value. Provide this feature via a new option in a FormControlOptions interface, based on AbstractControlOptions.

Also, expose the default value as part of the public API. This is part of a feature that has been requested elsewhere (e.g. in #19747).

This was originally proposed as part of typed forms. As discussed in the GDE session (and after with akushnir/alxhub), it is likely better to just reuse the initial value rather than accepting an additional default.

It is desirable to land this separately in order to reduce the scope of the typed forms PR, and make it a types-only change.

Pertains to issue #13721.

PR Close #44434
2021-12-15 10:36:13 -05:00
Dylan Hunn
5da31d6d25 test(forms): Add more tests for FormBuilder method argument shapes. (#44452)
It is possible to pass arguments to `FormBuilder` using four different formats: value-only, boxed value, control config, and value-array. Currently, these different methods are not well-tested, especially as they interact. This PR will add tests for the variety of different argument shapes.

This was originally inspired by typed forms: when `FormBuilder` becomes typed, all these argument shapes should just work, with correct inferred types.

PR Close #44452
2021-12-14 16:11:29 -05:00
Dylan Hunn
65717999c8 refactor(forms): Make the minimum changes to the forms unit tests in order to support the typed forms PR (#43834). (#44451)
Currently, many of our unit tests are written to use heterogenous groups and arrays, and controls that accept heterogenous values. This PR will make the minimum possible alterations to prepare those usages, mainly by annotating them as untyped controls, etc.

This PR is *not* intended to test typed forms, merely to minimize the size of the upcoming PR. This will allow that PR to be focused on the actual features and tests, rather than boilerplate fixes.

PR Close #44451
2021-12-14 16:10:08 -05:00
Dylan Hunn
815d4ceeef fix(forms): I indroduced a minor error in a previous PR: pendingValue is a value not a boolean flag. (#44450)
The bug should have no effect since it's a typings-only, internal-only bug, but it's good to fix nonetheless.

PR Close #44450
2021-12-14 16:09:42 -05:00
Dylan Hunn
7df9127088 refactor(forms): Fix weak helper types in the Forms package, mostly Function types that can be strengthened to specific callbacks. This was originally proposed as part of Typed Forms, but it may be possible to submit at least some of these changes separately and unconditionally (i.e. without relying on TypedOrUntyped.) (#44370)
It is desirable to land this separately to reduce the scope of the Typed Forms PR, by focusing it only on the new type parameters (rather than incidental strictness fixes).

PR Close #44370
2021-12-10 17:13:24 -05:00
Paul Gschwendtner
98c5063cd8 build: update visibility for npm package targets to work with new integration test structure (#44238)
As mentioned in the previous commit, integration tests will be declared
in subpackages of `//integration`. For these tests to still rely on the
NPM packages from `HEAD`, we need to update the visibility.

PR Close #44238
2021-12-08 13:42:41 -05:00
Alex Rickabaugh
0cd524b148 Revert "refactor(forms): Move FormControl to an overridden exported constructor. (#44316)"
This reverts commit cdf50ff931.

Reverting as this needs a little more work on the documentation side, plus
the `export declare interface` syntax in `model.ts` might have unintended
side effects in g3.
2021-12-08 13:36:58 -05:00
Dylan Hunn
cdf50ff931 refactor(forms): Move FormControl to an overridden exported constructor. (#44316)
This implementation change was originally proposed as part of Typed Forms, and will have major consequences for that project as described in the design doc. Submitting it separately will greatly simplify the risk of landing Typed Forms. This change should have no visible impact on normal users of FormControl.

See the Typed Forms design doc here: https://docs.google.com/document/d/1cWuBE-oo5WLtwkLFxbNTiaVQGNk8ipgbekZcKBeyxxo.

PR Close #44316
2021-12-08 13:24:28 -05:00
Andrew Kushnir
3f6d8f38de refactor(forms): minor refactoring of SelectMultipleControlValueAccessor (#44261)
This commit updates the code of the `SelectMultipleControlValueAccessor` to:
- improve typings to make them more precise
- updates the note that refers to IE, but we still can not remove the branch since it's needed for Universal (that uses Domino)

PR Close #44261
2021-11-30 16:43:11 -05:00
Ramesh Thiruchelvam
24baa5e61d docs(forms): add an example for async validator token (#44301)
to be consistent with the validator token, have the example code for the async validator token.

PR Close #44301
2021-11-30 14:24:26 -05:00
Ruslan Usmanov
ca5b9b558c refactor(forms): eagerly initialize data members (#44292)
Data members in AbstractControl should be eagerly
initialized to address issue/24571. This eliminates the need to
constantly check for truthiness and makes code much more readable.

More PRs to follow to address issue/24571.

PR Close #44292
2021-11-30 14:15:16 -05:00
Andrew Kushnir
38c02e13a5 fix(forms): make the FormControlStatus available as a public API (#44183)
This commit makes the `FormControlStatus` symbol available as a public API. The symbol itself
was intended to become a part of the public API, but due to the missing re-export, the symbol
remains private.

Fixes #44176.

PR Close #44183
2021-11-17 10:37:28 -08:00
Andrew Kushnir
65597d650b refactor(forms): inherit ngOnChanges hooks from the base class (#43945)
This commit updates the code of the min/max and minlength/maxlength validator directives to inherit `ngOnChanges` hooks from the base class (the `AbstractValidatorDirective` one), rather than implementing the hooks on the child classes. This was needed to avoid issues with hooks inheritance in ViewEngine, but since it's deprecated, the code can be cleaned up.

PR Close #43945
2021-11-17 10:36:40 -08:00
Roman Frołow
9f3791432c docs(forms): fix typo in toInteger() function (#44075)
PR Close #44075
2021-11-08 16:59:08 +00:00
iRealNirmal
1543aaedd6 refactor(forms): update minlength/maxlength to inherit abstractValidator (#43998)
Modified minlength and maxlength validator to inherit abstractValidator

For every validator type different PR will be raised as discussed in #42378.

Closes #42267

PR Close #43998
2021-11-05 20:09:53 +00:00
Jessica Janiuk
17be47e781 Revert "refactor(forms): update minlength/maxlength to inherit abstractValidator" (#43971)
This reverts commit 7b31b887f9.

PR Close #43971
2021-10-27 21:42:26 +00:00
iRealNirmal
5c22dfe861 refactor(forms): update minlength/maxlength to inherit abstractValidator (#43835)
Modified minlength and maxlength validator to inherit abstractValidator

For every validator type different PR will be raised as discussed in #42378.

Closes #42267

PR Close #43835
2021-10-26 20:24:40 +00:00
Joey Perrott
af1f8f8429 ci: remove saucelabs view engine tests (#43862)
Remove the view engine specific saucelabs test job and associated tags/tooling as view engine is no longer being tested
on CI.

PR Close #43862
2021-10-19 10:06:55 -07:00
Alex Rickabaugh
48aa0039ea refactor(compiler-cli): update peerDependencies to require rxjs ^7.4.0 (#43748)
RxJS 7 versions prior to 7.4.0 export ES5 code, whereas Angular
applications using RxJS 6 today use ES2015. This was fixed in RxJS 7.4.0
which exposes ES2015 entrypoints as well. This commit updates Angular's
peer dependencies to require the newer RxJS.

PR Close #43748
2021-10-06 15:57:59 -07:00
Paul Gschwendtner
e0a0d05d45 feat(core): update node version support range to support v16 (#43740)
This commit updates the `node` engines range for all Angular
framework packages to:

* No longer support NodeJS v12 `< 12.20`. This is done because APF v13
  uses package export patterns which are only supported as of v12.20.
  https://nodejs.org/api/packages.html#packages_subpath_patterns.

* Allows for the latest v16 NodeJS versions. This matches with the CLI
  which added NodeJS v16 support with https://github.com/angular/angular-cli/pull/21854.

  We already limit this to `>= v16.10.0` in preparation to only
  supporting the LTS minors of Node v16.

BREAKING CHANGE: NodeJS versions older than `v12.20.0` are no longer
supported due to the Angular packages using the NodeJS package exports
feature with subpath patterns.

PR Close #43740
2021-10-06 10:55:44 -07:00
Paul Gschwendtner
e6046c9420 refactor: remove entry_point attribute from ng_package targets (#43431)
With the changes to support APF v13 in the `ng_package` rule, we have
removed the ambiguous `entry_point` attribute. The attribute suggested
that it would be used for determining the primary entry-point input
file. This was not the case as the flat module output file is consulted
for bundling et at. The attribute has been renamed to match its
purposed (renamed to `primary_bundle_name`).

We no longer need to set that attribute because the primary bundle
name is (1) not of relevance for consumers and (2) the rule already
infers the bundle name properly from the Bazel package.

PR Close #43431
2021-10-01 18:28:42 +00:00
iRealNirmal
d9d8f950e9 feat(forms): allow disabling min/max validators dynamically (by setting the value to null) (#42978)
This commit updates the logic of the `min` and `max` validators to allow
disabling them dynamically in case `null` is provided as a value. For example: `<input
type="number" [min]="minValue">`, when `minValue` might be set to `null` in a
component class. This should allow `min` and `max` validators to be used for dynamic forms.

Note: similar support was added to the `minLength` and `maxLength`
validators earlier (see #42565).

PR Close #42978
2021-09-24 10:35:31 -07:00
Kristiyan Kostadinov
ea61ec2562 feat(core): support TypeScript 4.4 (#43281)
Adds support for TypeScript 4.4. High-level overview of the changes made in this PR:

* Bumps the various packages to `typescript@4.4.2` and `tslib@2.3.0`.
* The `useUnknownInCatchVariables` compiler option has been disabled so that we don't have to cast error objects explicitly everywhere.
* TS now passes in a third argument to the `__spreadArray` call inside child class constructors. I had to update a couple of places in the runtime and ngcc to be able to pick up the calls correctly.
* TS now generates code like `(0, foo)(arg1, arg2)` for imported function calls. I had to update a few of our tests to account for it. See https://github.com/microsoft/TypeScript/pull/44624.
* Our `ngtsc` test setup calls the private `matchFiles` function from TS. I had to update our usage, because a new parameter was added.
* There was one place where we were setting the readonly `hasTrailingComma` property. I updated the usage to pass in the value when constructing the object instead.
* Some browser types were updated which meant that I had to resolve some trivial type errors.
* The downlevel decorators tranform was running into an issue where the Closure synthetic comments were being emitted twice. I've worked around it by recreating the class declaration node instead of cloning it.

PR Close #43281
2021-09-23 14:49:19 -07:00
Kristiyan Kostadinov
c3968047b6 refactor(forms): make error messages easier to tree shake (#43223)
Currently the error message functions are defined as static methods on a class which means that as soon as one of them is used somewhere, all of them have to be retained. This isn't a problem at the moment, because all of them are behind `ngDevMode` checks, but it's error prone and it's easy to fix.

These changes move them out into functions so that they can be imported individually. It also has the advantage of allowing Webpack to minify the function names.

PR Close #43223
2021-08-26 10:05:36 -07:00
Dylan Hunn
e49fc96ed3 feat(forms): Make Form Statuses use stricter types. (#42952)
Specifically: narrow the type used for form statuses from string to a union of possible statuses. Change the API methods from any to use the new type.

This is a breaking change. However, as discussed in the PR, breakage seems minimal, and google3 has been prepped to land this.

Background: we uncovered these any typings in the course of design work for typed forms. They could be fixed in a non-breaking manner by piggybacking them on top of the new typed forms generics, but it would be much cleaner to fix them separately if possible.

BREAKING CHANGE:

A new type called `FormControlStatus` has been introduced, which is a union of all possible status strings for form controls. `AbstractControl.status` has been narrowed from `string` to `FormControlStatus`, and `statusChanges` has been narrowed from `Observable<any>` to `Observable<FormControlStatus>`. Most applications should consume the new types seamlessly. Any breakage caused by this change is likely due to one of the following two problems: (1) the app is comparing `AbstractControl.status` against a string which is not a valid status; or, (2) the app is using `statusChanges` events as if they were something other than strings.

PR Close #42952
2021-08-04 16:28:20 -07:00
Kristiyan Kostadinov
9a3cf661a2 refactor(core): update peerDependencies to allow rxjs7 (#42991)
We can't update the framework to rxjs7 until version 13, because it contains breaking changes, but we can allow users to opt into it since all of our code should be compatible.

These changes expand the allowed version range of rxjs and add an integration test to verify that we don't get compilation errors. Note that we also have a test that runs the AIO examples against rxjs 7 already (#42660).

Fixes #41897.

PR Close #42991
2021-08-02 13:55:01 -07:00
Dylan Hunn
1d9d02696e feat(forms): add hasValidators, addValidators, and removeValidators methods (for both sync and async) (#42838)
Several new functionalities are possible with this change: the most requested is that callers can now check whether a control has a required validator. Other uses include incrementally changing the validators set without doing an expensive operation to reset all validators.

Closes #13461.

PR Close #42838
2021-07-22 16:31:00 +00:00
iRealNirmal
a502279592 feat(forms): allow minLength/maxLength validator to be bound to null (#42565)
If the validator is bound to be `null` then no validation occurs and
attribute is not added to DOM.

For every validator type different PR will be raised as discussed in
https://github.com/angular/angular/pull/42378.

Closes #42267.

PR Close #42565
2021-07-21 22:35:59 +00:00
Paul Gschwendtner
b5ab7aff43 refactor: add override keyword to members implementing abstract declarations (#42512)
In combination with the TS `noImplicitOverride` compatibility changes,
we also want to follow the best-practice of adding `override` to
members which are implemented as part of abstract classes. This
commit fixes all instances which will be flagged as part of the
custom `no-implicit-override-abstract` TSLint rule.

PR Close #42512
2021-07-12 13:11:17 -07:00
Paul Gschwendtner
01e869a45b refactor(forms): ensure compatibility with noImplicitOverride (#42512)
Adds the `override` keyword to the `forms` sources to ensure
compatibility with `noImplicitOverride`.

PR Close #42512
2021-07-12 13:11:16 -07:00
David Gilson
ad08b17b05 docs(forms): add diff between add and set control (#42638)
PR Close #42638
2021-07-08 10:27:43 -07:00
Paul Gschwendtner
9db69a9c9e build: use api-golden tool from dev-infra for testing public API (#42688)
Switches our TS API guardian targets to rather use the new tool from
dev-infra that relies on Microsoft's API extractor.

PR Close #42688
2021-06-30 11:43:48 -07:00
Marius Bethge
f3a79878af docs(forms): correct sample code for FormArray.reset (#42477)
Remove unexpected this, correct output comment for arr.value and correct parameter type for FormArray.get().

PR Close #42477
2021-06-16 14:01:55 -07:00
Dylan Hunn
7180ec9e7c fix(forms): changes to status not always being emitted to statusChanges observable for async validators. (#42553)
When a FormControl, FormArray, or FormGroup is first constructed, if an async validator is attached, the `statusChanges` observable should receive a message when the validator complete (i.e. pending -> valid/invalid). If the validator was provided as part of the constructor options, it was not fired at construction time, which is fixed in this PR.

Fixes #35309.

PR Close #42553
2021-06-14 09:57:57 -07:00
Dylan Hunn
34ce635e3a feat(forms): undo revert and add ng-submitted class to forms that have been submitted. (#42132) (#42132)
As previously discussed in pull/31070 and issues/30486, this would be useful because it is often desirable to apply styles to fields that are both `ng-invalid` and `ng-pristine` after the first attempt at form submission, but Angular does not provide any simple way to do this (although evidently Angularjs did). This will now be possible with a descendant selector such as `.ng-submitted .ng-invalid`.

In this implementation, the directive that sets control status classes on forms and formGroups has its set of statuses widened to include `ng-submitted`. Then, in the event that `is('submitted')` is invoked, the `submitted` property of the control container is returned iff it exists. This is preferred over checking whether the container is a `Form` or `FormGroup` directly to avoid reflecting on those classes.

Closes #30486.

PR Close #42132.

This reverts commit 00b1444d12, undoing the rollback of this change.

PR Close #42132
2021-06-08 14:02:29 -07:00
Paul Gschwendtner
2d0ff0a5d3 ci: add lint error for files with missing trailing new-line (#42478)
For quite a while it is an unspoken convention to add a trailing
new-line files within the Angular repository. This was never enforced
automatically, but has been frequently raised in pull requests through
manual review. This commit sets up a lint rule so that this is
"officially" enforced and doesn't require manual review.

PR Close #42478
2021-06-04 13:31:03 -07:00
Paul Gschwendtner
25f763cff8 feat(core): support TypeScript 4.3 (#42022)
Switches the repository to TypeScript 4.3 and the latest
version of tslib. This involves updating the peer dependency
ranges on `typescript` for the compiler CLI and for the Bazel
package. Tests for new TypeScript features have been added to
ensure compatibility with Angular's ngtsc compiler.

PR Close #42022
2021-06-04 11:17:09 -07:00
Jessica Janiuk
00b1444d12 Revert "feat(forms): add ng-submitted class to forms that have been submitted." (#42474)
This reverts commit f024d7556081f8913f21761bb8e6aab8d08be110.

PR Close #42474
2021-06-03 17:42:02 -07:00
Dylan Hunn
47270d9e63 feat(forms): add ng-submitted class to forms that have been submitted. (#42132)
As previously discussed in pull/31070 and issues/30486, this would be useful because it is often desirable to apply styles to fields that are both `ng-invalid` and `ng-pristine` after the first attempt at form submission, but Angular does not provide any simple way to do this (although evidently Angularjs did). This will now be possible with a descendant selector such as `.ng-submitted .ng-invalid`.

In this implementation, the directive that sets control status classes on forms and formGroups has its set of statuses widened to include `ng-submitted`. Then, in the event that `is('submitted')` is invoked, the `submitted` property of the control container is returned iff it exists. This is preferred over checking whether the container is a `Form` or `FormGroup` directly to avoid reflecting on those classes.

Closes #30486.

PR Close #42132
2021-06-03 13:21:29 -07:00
iRealNirmal
751cd83ae3 fix(forms): the min and max validators should work correctly with 0 as a value (#42412)
Prior to this change the `min` and `max` validator directives would not
set the `min` and `max` attributes on the host element. The problem was
caused by the truthy check in host binding expression that was
calculated as `false` when `0` is used as a value. This commit updates
the logic to leverage nullish coalescing operator in these host binding
expressions, so `0` is treated as a valid value, thus the `min` and
`max` attributes are set correctly.

Partially closes #42267

PR Close #42412
2021-06-03 11:34:46 -07:00
Kristiyan Kostadinov
a787f78074 test: clean up internal testing utilities (#42177)
We have some internal proxies for all of the Jasmine functions, as well as some other helpers. This code hasn't been touched in more than 5 years, it can lead to confusion and it isn't really necessary since the same can be achieved using Jasmine.

These changes remove most of the code and clean up our existing unit tests.

PR Close #42177
2021-05-26 20:07:25 +00:00
iRealNirmal
3d9062dad7 fix(forms): Add float number support for min and max validator (#42223)
Added float number support for minValidator and maxValidator

Closes #42215

PR Close #42223
2021-05-25 20:31:09 +00:00
Joey Perrott
324bd89114 build(forms): update supported range of node versions to be less restrictive (#42205)
Update the supported range of node versions for to be less restrictive, no longer causing
yarn or npm to fail engine's checks for future versions of node.

While this change will no longer cause yarn or npm to fail these engine's check, this does
not reflect a change in the officially supported versions of node for Angular.  Angular
continues to maintain support for Active LTS and Maintenance LTS versions of node.

PR Close #42205
2021-05-25 17:48:46 +00:00
Joey Perrott
2dd956421c build: remove publishConfig entry from package.json entries (#42104)
Remove publishConfig property from the package.json entry for each of the entries in
the publish configuration.  Using the wombat proxy is now ensured/managed by the
ng-dev release tooling.

PR Close #42104
2021-05-18 15:41:33 -07:00
Dylan Hunn
a4ebe8656e fix(forms): registerOnValidatorChange should be called for ngModelGroup. (#41971)
The Validator and AsyncValidator interfaces provide a callback, `registerOnValidatorChange(fn)`. `registerOnValidatorChange` is supposed to be fired at least once to register `fn` with the validator. `fn` is then called by the validator whenever its inputs change. This was previously not happening for FormGroup validators, and is now fixed.

PR Close #41971
2021-05-13 13:57:47 -04:00