-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(front): util functions for determining form state
- Loading branch information
Showing
3 changed files
with
43 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { FormGroup } from '@angular/forms'; | ||
|
||
/** | ||
* Returns true if a group is valid and dirty. | ||
*/ | ||
export function groupIsComplete(group: FormGroup): boolean { | ||
return group.dirty && group.valid; | ||
} | ||
|
||
/** | ||
* Returns true if group contains a dirty invalid control. | ||
* | ||
* A formgroup can be dirty by virtue of one control being dirty, and invalid by | ||
* virtue of a pristine control being invalid. But it's usually too early to | ||
* show an error message at this point, because they simply haven't finished | ||
* filling in the form. | ||
* | ||
* Use this check to determine if there's a control that's genuinely dirty and | ||
* invalid, in which case you probably *do* want to yell at the user. | ||
*/ | ||
export function groupIsActuallyInvalid(group: FormGroup): boolean { | ||
return Object.values(group.controls).some((c) => c.dirty && c.invalid); | ||
} | ||
|
||
/* | ||
* Return true if group is invalid but doesn't have any dirty invalid | ||
* controls. | ||
* | ||
* This is true for a pristine group, and only becomes false when (a) the form | ||
* complete and valid, or (b) the form has a dirty, invalid control. | ||
* | ||
* | ||
*/ | ||
export function groupIsIncomplete(group: FormGroup): boolean { | ||
return !groupIsActuallyInvalid(group) && !group.valid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './unsub.class'; | ||
export * from './grouped-map-leaderboards.util'; | ||
export * from './grouped-map-credits.class'; | ||
export * as FormUtils from './form-utils.util'; |