import { FormArray , FormGroup } from '@angular/forms' ; import * as _ from 'underscore.string' ; export class FormHelpers { param { FormGroup } formGroup param markAs param opts static deepMark ( formGroup , markAs , opts = { onlySelf : false } ) { Object . values ( formGroup . controls ) . forEach ( ( c ) => { if ( c instanceof FormGroup || c instanceof FormArray ) { FormHelpers . deepMark ( c , markAs , opts ) ; } else { c [ `markAs${ _ . capitalize ( markAs ) }` ] ( opts ) ; } } ) ; } param { FormGroup } formGroup param control returns static isInvalidControl ( formGroup , control ) { if ( ! formGroup . contains ( control ) ) { return true ; } return ( ( formGroup . get ( control ) . touched || formGroup . get ( control ) . dirty ) && formGroup . get ( control ) . invalid ) ; } param { FormGroup } formGroup param control returns static isValidControl ( formGroup , control ) { if ( ! formGroup . contains ( control ) ) { return false ; } return ( ( formGroup . get ( control ) . touched || formGroup . get ( control ) . dirty ) && formGroup . get ( control ) . valid ) ; } }