Skip to content

Commit 3739fa4

Browse files
committed
96252: Move dynamic forms out of AppModule
1 parent 8341882 commit 3739fa4

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

src/app/access-control/access-control.module.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import { MembersListComponent } from './group-registry/group-form/members-list/m
1010
import { SubgroupsListComponent } from './group-registry/group-form/subgroup-list/subgroups-list.component';
1111
import { GroupsRegistryComponent } from './group-registry/groups-registry.component';
1212
import { FormModule } from '../shared/form/form.module';
13+
import { DYNAMIC_ERROR_MESSAGES_MATCHER, DynamicErrorMessagesMatcher } from '@ng-dynamic-forms/core';
14+
import { AbstractControl } from '@angular/forms';
15+
16+
/**
17+
* Condition for displaying error messages on email form field
18+
*/
19+
export const ValidateEmailErrorStateMatcher: DynamicErrorMessagesMatcher =
20+
(control: AbstractControl, model: any, hasFocus: boolean) => {
21+
return (control.touched && !hasFocus) || (control.errors?.emailTaken && hasFocus);
22+
};
1323

1424
@NgModule({
1525
imports: [
@@ -26,6 +36,12 @@ import { FormModule } from '../shared/form/form.module';
2636
GroupFormComponent,
2737
SubgroupsListComponent,
2838
MembersListComponent
39+
],
40+
providers: [
41+
{
42+
provide: DYNAMIC_ERROR_MESSAGES_MATCHER,
43+
useValue: ValidateEmailErrorStateMatcher
44+
},
2945
]
3046
})
3147
/**

src/app/app.module.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
88
import { EffectsModule } from '@ngrx/effects';
99
import { RouterStateSerializer, StoreRouterConnectingModule } from '@ngrx/router-store';
1010
import { MetaReducer, StoreModule, USER_PROVIDED_META_REDUCERS } from '@ngrx/store';
11-
import { DYNAMIC_ERROR_MESSAGES_MATCHER, DYNAMIC_MATCHER_PROVIDERS, DynamicErrorMessagesMatcher } from '@ng-dynamic-forms/core';
1211
import { TranslateModule } from '@ngx-translate/core';
1312
import { ScrollToModule } from '@nicky-lenaers/ngx-scroll-to';
1413
import { AppRoutingModule } from './app-routing.module';
@@ -28,7 +27,6 @@ import { XsrfInterceptor } from './core/xsrf/xsrf.interceptor';
2827
import { LogInterceptor } from './core/log/log.interceptor';
2928
import { EagerThemesModule } from '../themes/eager-themes.module';
3029
import { APP_CONFIG, AppConfig } from '../config/app-config.interface';
31-
import { NgxMaskModule } from 'ngx-mask';
3230
import { StoreDevModules } from '../config/store/devtools';
3331
import { RootModule } from './root.module';
3432

@@ -46,14 +44,6 @@ export function getMetaReducers(appConfig: AppConfig): MetaReducer<AppState>[] {
4644
return appConfig.debug ? [...appMetaReducers, ...debugMetaReducers] : appMetaReducers;
4745
}
4846

49-
/**
50-
* Condition for displaying error messages on email form field
51-
*/
52-
export const ValidateEmailErrorStateMatcher: DynamicErrorMessagesMatcher =
53-
(control: AbstractControl, model: any, hasFocus: boolean) => {
54-
return (control.touched && !hasFocus) || (control.errors?.emailTaken && hasFocus);
55-
};
56-
5747
const IMPORTS = [
5848
CommonModule,
5949
SharedModule,
@@ -64,7 +54,6 @@ const IMPORTS = [
6454
ScrollToModule.forRoot(),
6555
NgbModule,
6656
TranslateModule.forRoot(),
67-
NgxMaskModule.forRoot(),
6857
EffectsModule.forRoot(appEffects),
6958
StoreModule.forRoot(appReducers, storeModuleConfig),
7059
StoreRouterConnectingModule.forRoot(),
@@ -113,11 +102,6 @@ const PROVIDERS = [
113102
useClass: LogInterceptor,
114103
multi: true
115104
},
116-
{
117-
provide: DYNAMIC_ERROR_MESSAGES_MATCHER,
118-
useValue: ValidateEmailErrorStateMatcher
119-
},
120-
...DYNAMIC_MATCHER_PROVIDERS,
121105
];
122106

123107
const DECLARATIONS = [

src/app/shared/form/form.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { DsDynamicLookupRelationExternalSourceTabComponent } from './builder/ds-
2121
import { SharedModule } from '../shared.module';
2222
import { TranslateModule } from '@ngx-translate/core';
2323
import { SearchModule } from '../search/search.module';
24-
import { DYNAMIC_FORM_CONTROL_MAP_FN, DynamicFormLayoutService, DynamicFormsCoreModule, DynamicFormService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
24+
import { DYNAMIC_FORM_CONTROL_MAP_FN, DYNAMIC_MATCHER_PROVIDERS, DynamicFormLayoutService, DynamicFormsCoreModule, DynamicFormService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
2525
import { ExistingMetadataListElementComponent } from './builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component';
2626
import { ExistingRelationListElementComponent } from './builder/ds-dynamic-form-ui/existing-relation-list-element/existing-relation-list-element.component';
2727
import { ExternalSourceEntryImportModalComponent } from './builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component';
@@ -36,6 +36,7 @@ import { VocabularyTreeviewService } from './vocabulary-treeview/vocabulary-tree
3636
import { FormBuilderService } from './builder/form-builder.service';
3737
import { DsDynamicTypeBindRelationService } from './builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service';
3838
import { FormService } from './form.service';
39+
import { NgxMaskModule } from 'ngx-mask';
3940

4041
const COMPONENTS = [
4142
CustomSwitchComponent,
@@ -82,6 +83,7 @@ const DIRECTIVES = [
8283
SharedModule,
8384
TranslateModule,
8485
SortablejsModule,
86+
NgxMaskModule.forRoot(),
8587
],
8688
exports: [
8789
...COMPONENTS,
@@ -92,6 +94,7 @@ const DIRECTIVES = [
9294
provide: DYNAMIC_FORM_CONTROL_MAP_FN,
9395
useValue: dsDynamicFormControlMapFn
9496
},
97+
...DYNAMIC_MATCHER_PROVIDERS,
9598
VocabularyTreeviewService,
9699
DynamicFormLayoutService,
97100
DynamicFormService,

0 commit comments

Comments
 (0)