feat(forms): add ng-submitted class to forms that have been submitted.#42132
feat(forms): add ng-submitted class to forms that have been submitted.#42132dylhunn wants to merge 1 commit intoangular:masterfrom
ng-submitted class to forms that have been submitted.#42132Conversation
1c9e212 to
b39597c
Compare
AndrewKushnir
left a comment
There was a problem hiding this comment.
@dylhunn great start, the changes are in the right direction 👍
There are few comments that I've left + I think we'd need to add more tests (to verify the fact that only the top-level form groups receive ng-submitted class). I will write a separate comment related to tests and just want to share the rest of the feedback, so you can have a look at it meanwhile.
Thank you.
b39597c to
3f72c22
Compare
|
@dylhunn just wanted to share some test cases that I think would be great to have. Some of them after already fully covered (for ex. "Template-driven Forms" -> Case 2), I listed the cases anyways just to have a full picture (for myself, so I'm not missing anything). I also mentioned what we can look for in the tests, to make sure we do not assign extra classes to elements that are not expected to have that class. Reactive Forms1. Simple case:We can check that:
2. With nested
|
|
@dylhunn quick note: we should also update the relevant section of the |
3f72c22 to
9f29443
Compare
AndrewKushnir
left a comment
There was a problem hiding this comment.
The changes look good, thanks @dylhunn 👍
Just left a few comments related to tests.
9f29443 to
c5a7109
Compare
415cfb9 to
f024d75
Compare
|
Merging is currently blocked on a g3 presubmit issue, as described internally in b/189261737. |
|
Some updates:
|
|
This PR caused breakages in google3 and was rolled back. We'll need to run a TGP with these changes to verify there are no issues. |
f024d75 to
cd22c7a
Compare
efcc737 to
4f09d5a
Compare
4f09d5a to
eeb89d4
Compare
…e been submitted. (angular#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 angular#30486. PR Close angular#42132. This reverts commit 00b1444, undoing the rollback of this change.
eeb89d4 to
163af75
Compare
|
The issue seems to have been that ViewEngine chokes on the spread operator as used in the host binding. I'll investigate this more separately, but it should be fixed here for now. |
|
After re-running flakes, TGP looks good (googler link). |
| '[class.ng-pending]': 'is("pending")', | ||
| }; | ||
|
|
||
| export const ngGroupStatusHost = { |
There was a problem hiding this comment.
@dylhunn could you please create a followup PR to add some information on why the content of the ngGroupStatusHost object partially duplicates the ngControlStatusHost one (related to spread operator support in ViewEngine and the need to refactor the code once ViewEngine is removed)?
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: 30486
Currently, no status class is set on a form to show that it has been submitted. 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-invalidandng-pristineafter the first attempt at form submission, but Angular does not currently provide any simple way to do this (although evidently Angularjs did).What is the new behavior?
A new
ng-submittedclass is set on submitted forms. It will now be possible to select untouched but invalid fields in a submitted form (for example, with a 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 thatis('submitted')is invoked, thesubmittedproperty of the control container is returned iff it exists. This is preferred over checking whether the container is aFormorFormGroupdirectly to avoid reflecting on those classes.Does this PR introduce a breaking change?
Other information
Closes #30486.
Closes #31070.