Skip to content

Commit

Permalink
feat(accessibility): set focus to first invalid form field (#1694)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreassteinmann committed Sep 4, 2024
1 parent aae9d6c commit 4a1620f
Show file tree
Hide file tree
Showing 37 changed files with 133 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FormlyFieldConfig } from '@ngx-formly/core';
import { AppFacade } from 'ish-core/facades/app.facade';
import { CostCenterBuyer } from 'ish-core/models/cost-center/cost-center.model';
import { PriceHelper } from 'ish-core/models/price/price.helper';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { FormsService } from 'ish-shared/forms/utils/forms.service';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
Expand Down Expand Up @@ -87,6 +87,7 @@ export class CostCenterBuyerEditDialogComponent implements OnInit {
if (this.costCenterBuyerForm.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.costCenterBuyerForm);
focusFirstInvalidField(this.costCenterBuyerForm);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AppFacade } from 'ish-core/facades/app.facade';
import { CostCenterBuyer } from 'ish-core/models/cost-center/cost-center.model';
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { PriceHelper } from 'ish-core/models/price/price.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { FormsService } from 'ish-shared/forms/utils/forms.service';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
Expand Down Expand Up @@ -160,6 +160,7 @@ export class CostCenterBuyersPageComponent implements OnInit {
if (this.form.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.form);
focusFirstInvalidField(this.form);
return;
}
const buyers: CostCenterBuyer[] = this.model.addBuyers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UntypedFormGroup } from '@angular/forms';
import { Observable } from 'rxjs';

import { CostCenterBase } from 'ish-core/models/cost-center/cost-center.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';

Expand All @@ -28,6 +28,7 @@ export class CostCenterCreatePageComponent implements OnInit {
if (this.form.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.form);
focusFirstInvalidField(this.form);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UntypedFormGroup } from '@angular/forms';
import { Observable } from 'rxjs';

import { CostCenter, CostCenterBase } from 'ish-core/models/cost-center/cost-center.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';

Expand All @@ -30,6 +30,7 @@ export class CostCenterEditPageComponent implements OnInit {
if (this.form.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.form);
focusFirstInvalidField(this.form);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Observable } from 'rxjs';
import { v4 as uuid } from 'uuid';

import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';
Expand Down Expand Up @@ -45,6 +45,7 @@ export class UserCreatePageComponent implements OnInit {
if (this.form.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.form);
focusFirstInvalidField(this.form);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UntypedFormGroup } from '@angular/forms';
import { Observable } from 'rxjs';

import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';
Expand Down Expand Up @@ -33,6 +33,7 @@ export class UserEditBudgetPageComponent implements OnInit {
if (this.budgetForm.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.budgetForm);
focusFirstInvalidField(this.budgetForm);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UntypedFormGroup } from '@angular/forms';
import { Observable } from 'rxjs';

import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';
Expand Down Expand Up @@ -33,6 +33,7 @@ export class UserEditProfilePageComponent implements OnInit {
if (this.profileForm.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.profileForm);
focusFirstInvalidField(this.profileForm);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FormGroup } from '@angular/forms';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { FormlyFieldConfig } from '@ngx-formly/core';

import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

/**
* The Wishlist Reject Approval Dialog shows the modal to reject a requisition.
Expand Down Expand Up @@ -77,6 +77,7 @@ export class RequisitionRejectDialogComponent implements OnInit {
if (this.rejectForm.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.rejectForm);
focusFirstInvalidField(this.rejectForm);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { map, shareReplay, startWith } from 'rxjs/operators';

import { AccountFacade } from 'ish-core/facades/account.facade';
import { Contact } from 'ish-core/models/contact/contact.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { ContactUsFacade } from '../../../facades/contact-us.facade';

Expand Down Expand Up @@ -130,6 +130,7 @@ export class ContactFormComponent implements OnInit {
this.request.emit(this.contactForm.value);
} else {
markAsDirtyRecursive(this.contactForm);
focusFirstInvalidField(this.contactForm);
this.submitted = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { pick } from 'lodash-es';

import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

import { OrderTemplate } from '../../models/order-template/order-template.model';
Expand Down Expand Up @@ -99,6 +99,7 @@ export class OrderTemplatePreferencesDialogComponent implements OnInit {
if (this.orderTemplateForm.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.orderTemplateForm);
focusFirstInvalidField(this.orderTemplateForm);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Observable, of } from 'rxjs';
import { filter, map, take } from 'rxjs/operators';

import { SelectOption } from 'ish-core/models/select-option/select-option.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { OrderTemplatesFacade } from '../../facades/order-templates.facade';

Expand Down Expand Up @@ -73,11 +73,13 @@ export class SelectOrderTemplateModalComponent implements OnInit {
this.submitExisting(radioButtons.orderTemplate);
} else {
markAsDirtyRecursive(this.formGroup);
focusFirstInvalidField(this.formGroup);
}
} else if (radioButtons.newOrderTemplate && this.formGroup.valid) {
this.submitNew(radioButtons.newOrderTemplate);
} else {
markAsDirtyRecursive(this.formGroup);
focusFirstInvalidField(this.formGroup);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AppFacade } from 'ish-core/facades/app.facade';
import { ProductContextFacade } from 'ish-core/facades/product-context.facade';
import { ProductView } from 'ish-core/models/product-view/product-view.model';
import { whenTruthy } from 'ish-core/utils/operators';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { ProductNotificationsFacade } from '../../facades/product-notifications.facade';
import { ProductNotification } from '../../models/product-notification/product-notification.model';
Expand Down Expand Up @@ -111,6 +111,7 @@ export class ProductNotificationEditDialogComponent implements OnInit {
submitForm() {
if (this.productNotificationForm.invalid) {
markAsDirtyRecursive(this.productNotificationForm);
focusFirstInvalidField(this.productNotificationForm);
this.submitted = true;
return;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Observable, filter, map, shareReplay, take } from 'rxjs';

import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { SelectOption } from 'ish-core/models/select-option/select-option.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

import { PunchoutFacade } from '../../../facades/punchout.facade';
Expand Down Expand Up @@ -159,6 +159,7 @@ export class OciConfigurationFormComponent implements OnInit {
if (this.form.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.form);
focusFirstInvalidField(this.form);
return;
}
this.punchoutFacade.updateOciConfiguration(this.form.value.ociConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FormlyFieldConfig } from '@ngx-formly/core';
import { Observable } from 'rxjs';

import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { PunchoutFacade } from '../../../facades/punchout.facade';
import { CxmlConfiguration } from '../../../models/cxml-configuration/cxml-configuration.model';
Expand Down Expand Up @@ -78,6 +78,7 @@ export class CxmlConfigurationFormComponent implements OnDestroy, OnInit {
if (this.form.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.form);
focusFirstInvalidField(this.form);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output
import { UntypedFormGroup } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';

import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

import { PunchoutType, PunchoutUser } from '../../models/punchout-user/punchout-user.model';
Expand Down Expand Up @@ -127,6 +127,7 @@ export class PunchoutUserFormComponent implements OnInit {
if (this.form.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.form);
focusFirstInvalidField(this.form);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FormlyFieldConfig } from '@ngx-formly/core';
import { Observable, map, tap } from 'rxjs';

import { AccountFacade } from 'ish-core/facades/account.facade';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { ProductReviewsFacade } from '../../facades/product-reviews.facade';
import { ProductReview } from '../../models/product-reviews/product-review.model';
Expand Down Expand Up @@ -124,6 +124,7 @@ export class ProductReviewCreateDialogComponent implements OnInit {
submitForm(sku: string) {
if (this.form.invalid) {
markAsDirtyRecursive(this.form);
focusFirstInvalidField(this.form);
this.submitted = true;
return;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { filter, map, take, withLatestFrom } from 'rxjs/operators';

import { SelectOption } from 'ish-core/models/select-option/select-option.model';
import { whenTruthy } from 'ish-core/utils/operators';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

import { WishlistsFacade } from '../../facades/wishlists.facade';

Expand Down Expand Up @@ -70,11 +70,13 @@ export class SelectWishlistModalComponent implements OnInit {
this.submitExisting(radioButtons.wishlist);
} else {
markAsDirtyRecursive(this.formGroup);
focusFirstInvalidField(this.formGroup);
}
} else if (radioButtons.newList && this.formGroup.valid) {
this.submitNew(radioButtons.newList);
} else {
markAsDirtyRecursive(this.formGroup);
focusFirstInvalidField(this.formGroup);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { pick } from 'lodash-es';

import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

import { Wishlist } from '../../models/wishlist/wishlist.model';
Expand Down Expand Up @@ -112,6 +112,7 @@ export class WishlistPreferencesDialogComponent implements OnInit {
if (this.wishListForm.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.wishListForm);
focusFirstInvalidField(this.wishListForm);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { pick } from 'lodash-es';
import { Customer } from 'ish-core/models/customer/customer.model';
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { FieldLibrary } from 'ish-shared/formly/field-library/field-library';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

/**
* The Account Profile Company Page Component displays a form for changing a business customers' company data
Expand Down Expand Up @@ -42,6 +42,7 @@ export class AccountProfileCompanyComponent implements OnInit {
if (this.accountProfileCompanyForm.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.accountProfileCompanyForm);
focusFirstInvalidField(this.accountProfileCompanyForm);
return;
}
const companyName = this.accountProfileCompanyForm.get('companyName').value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FormlyFieldConfig } from '@ngx-formly/core';
import { Credentials } from 'ish-core/models/credentials/credentials.model';
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { User } from 'ish-core/models/user/user.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

/**
Expand Down Expand Up @@ -95,6 +95,7 @@ export class AccountProfileEmailComponent implements OnInit {
if (this.form.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.form);
focusFirstInvalidField(this.form);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FormGroup } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';

import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

/**
Expand Down Expand Up @@ -110,6 +110,7 @@ export class AccountProfilePasswordComponent implements OnInit, OnChanges {
if (this.accountProfilePasswordForm.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.accountProfilePasswordForm);
focusFirstInvalidField(this.accountProfilePasswordForm);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AppFacade } from 'ish-core/facades/app.facade';
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { User } from 'ish-core/models/user/user.model';
import { FieldLibrary } from 'ish-shared/formly/field-library/field-library';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { focusFirstInvalidField, markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';

interface ComponentState {
currentUser: User;
Expand Down Expand Up @@ -94,6 +94,7 @@ export class AccountProfileUserComponent extends RxState<ComponentState> impleme
if (this.accountProfileUserForm.invalid) {
this.submitted = true;
markAsDirtyRecursive(this.accountProfileUserForm);
focusFirstInvalidField(this.accountProfileUserForm);
return;
}

Expand Down
Loading

0 comments on commit 4a1620f

Please sign in to comment.