Skip to content

Commit

Permalink
bc address bug
Browse files Browse the repository at this point in the history
  • Loading branch information
carolcarpenter committed Oct 22, 2024
1 parent 5cb6d8e commit a99979d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ export abstract class BusinessApplicationHelper extends ApplicationHelper {
postalCode: new FormControl('', [FormControlValidators.required]),
province: new FormControl('', [
FormControlValidators.required,
FormControlValidators.requiredValue(SPD_CONSTANTS.address.provinceBC),
FormControlValidators.requiredValue(SPD_CONSTANTS.address.provinceBritishColumbia),
FormControlValidators.requiredValue(
SPD_CONSTANTS.address.provinceBC,
SPD_CONSTANTS.address.provinceBritishColumbia
),
]),
country: new FormControl('', [
FormControlValidators.required,
FormControlValidators.requiredValue(SPD_CONSTANTS.address.countryCA),
FormControlValidators.required,
FormControlValidators.requiredValue(SPD_CONSTANTS.address.countryCanada),
FormControlValidators.requiredValue(SPD_CONSTANTS.address.countryCA, SPD_CONSTANTS.address.countryCanada),
]),
});

Expand Down Expand Up @@ -320,10 +320,15 @@ export abstract class BusinessApplicationHelper extends ApplicationHelper {
postalCode: new FormControl('', [FormControlValidators.required]),
province: new FormControl('', [
FormControlValidators.required,
FormControlValidators.requiredValue(SPD_CONSTANTS.address.provinceBC),
FormControlValidators.requiredValue(SPD_CONSTANTS.address.provinceBritishColumbia),
FormControlValidators.requiredValue(
SPD_CONSTANTS.address.provinceBC,
SPD_CONSTANTS.address.provinceBritishColumbia
),
]),
country: new FormControl('', [
FormControlValidators.required,
FormControlValidators.requiredValue(SPD_CONSTANTS.address.countryCA, SPD_CONSTANTS.address.countryCanada),
]),
country: new FormControl('', [FormControlValidators.required, FormControlValidators.requiredValue('Canada')]),
branchManager: new FormControl('', [FormControlValidators.required]),
branchPhoneNumber: new FormControl(''),
branchEmailAddr: new FormControl('', [FormControlValidators.email]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,18 @@ export class FormControlValidators {
* @description
* Checks the form control must have a specific value.
*/
public static requiredValue(matchValue: string): ValidatorFn {
public static requiredValue(matchValue: string, otherMatchValue: string | null = null): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
if (!control.value) {
return null;
}
if (!matchValue) {
return null;
}
const valid = control.valid && control.value === matchValue;
let valid = control.valid && control.value === matchValue;
if (otherMatchValue && !valid) {
valid = control.valid && control.value === otherMatchValue;
}
return valid ? null : { requiredValue: true };
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import { Address } from './address-autocomplete.component';
<input matInput formControlName="province" maxlength="100" />
<mat-error *ngIf="form.get('province')?.hasError('required')">This is required</mat-error>
<mat-error *ngIf="form.get('province')?.hasError('requiredValue')"
>This must be '{{ provinceOfBC }}'</mat-error
>This must be '{{ provinceOfBC }}' or '{{ provinceBritishColumbia }}'</mat-error
>
</mat-form-field>
</div>
Expand All @@ -78,7 +78,9 @@ import { Address } from './address-autocomplete.component';
<mat-label>Country</mat-label>
<input matInput formControlName="country" maxlength="100" />
<mat-error *ngIf="form.get('country')?.hasError('required')">This is required</mat-error>
<mat-error *ngIf="form.get('country')?.hasError('requiredValue')">This must be 'Canada'</mat-error>
<mat-error *ngIf="form.get('country')?.hasError('requiredValue')"
>This must be '{{ countryCA }}' or '{{ countryCanada }}'</mat-error
>
</mat-form-field>
</div>
</div>
Expand All @@ -89,7 +91,11 @@ import { Address } from './address-autocomplete.component';
})
export class AddressComponent implements OnInit {
matcher = new FormErrorStateMatcher();

provinceOfBC = SPD_CONSTANTS.address.provinceBC;
provinceBritishColumbia = SPD_CONSTANTS.address.provinceBritishColumbia;
countryCA = SPD_CONSTANTS.address.countryCA;
countryCanada = SPD_CONSTANTS.address.countryCanada;

@Input() form!: FormGroup;
@Input() isWideView = false;
Expand Down

0 comments on commit a99979d

Please sign in to comment.