├── .editorconfig
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── angular.json
├── browserslist
├── e2e
├── protractor.conf.js
├── src
│ ├── app.e2e-spec.ts
│ └── app.po.ts
└── tsconfig.json
├── karma.conf.js
├── package.json
├── projects
└── xtream
│ └── ngx-validation-errors
│ ├── README.md
│ ├── karma.conf.js
│ ├── ng-package.json
│ ├── package.json
│ ├── src
│ ├── lib
│ │ ├── error-validation-config.ts
│ │ ├── form-array-container.component.ts
│ │ ├── form-field-container.component.ts
│ │ ├── form-field-empty-container.directive.ts
│ │ ├── form-validation-container.ts
│ │ ├── injection-tokens.ts
│ │ ├── inner-map-to-message.pipe.ts
│ │ ├── input-errors.component.scss
│ │ ├── input-errors.component.ts
│ │ ├── map-to-message.pipe.ts
│ │ ├── ngx-validation-errors.module.ts
│ │ ├── toChangeObservable.ts
│ │ ├── utils.ts
│ │ └── validation-context.component.ts
│ ├── public-api.ts
│ └── test.ts
│ ├── tsconfig.lib.json
│ ├── tsconfig.lib.prod.json
│ ├── tsconfig.spec.json
│ └── tslint.json
├── src
├── app
│ ├── app-routing.module.ts
│ ├── app.component.html
│ ├── app.component.scss
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── custom-errors
│ │ ├── custom-errors.component.html
│ │ ├── custom-errors.component.scss
│ │ └── custom-errors.component.ts
│ ├── errors-mapping.ts
│ ├── lazy
│ │ ├── lazy-form
│ │ │ ├── lazy-form.component.css
│ │ │ ├── lazy-form.component.html
│ │ │ └── lazy-form.component.ts
│ │ ├── lazy-routing.module.ts
│ │ └── lazy.module.ts
│ ├── main-from
│ │ ├── main-from.component.css
│ │ ├── main-from.component.html
│ │ └── main-from.component.ts
│ ├── material-from
│ │ ├── material-from.component.css
│ │ ├── material-from.component.html
│ │ └── material-from.component.ts
│ ├── shared
│ │ ├── form-submit.directive.ts
│ │ └── shared.module.ts
│ ├── simple-error-pipe.pipe.ts
│ └── simple-messages-provider.service.ts
├── assets
│ ├── .gitkeep
│ ├── i18n
│ │ ├── en.json
│ │ └── it.json
│ └── images
│ │ ├── logo-blu.svg
│ │ └── logo-white.svg
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── favicon.ico
├── index.html
├── main.ts
├── polyfills.ts
├── styles.scss
└── test.ts
├── tsconfig.app.json
├── tsconfig.json
├── tsconfig.spec.json
└── tslint.json
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.ts]
12 | quote_type = single
13 |
14 | [*.md]
15 | max_line_length = off
16 | trim_trailing_whitespace = false
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 | # Only exists if Bazel was run
8 | /bazel-out
9 |
10 | # dependencies
11 | /node_modules
12 |
13 | # profiling files
14 | chrome-profiler-events*.json
15 | speed-measure-plugin*.json
16 |
17 | # IDEs and editors
18 | /.idea
19 | .project
20 | .classpath
21 | .c9/
22 | *.launch
23 | .settings/
24 | *.sublime-workspace
25 |
26 | # IDE - VSCode
27 | .vscode/*
28 | !.vscode/settings.json
29 | !.vscode/tasks.json
30 | !.vscode/launch.json
31 | !.vscode/extensions.json
32 | .history/*
33 |
34 | # misc
35 | /.sass-cache
36 | /connect.lock
37 | /coverage
38 | /libpeerconnection.log
39 | npm-debug.log
40 | yarn-error.log
41 | testem.log
42 | /typings
43 |
44 | # System Files
45 | .DS_Store
46 | Thumbs.db
47 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # [2.1.0](https://github.com/xtreamsrl/ngx-validation-errors/compare/v2.0.0...v2.1.0) (2020-07-13)
2 |
3 |
4 | ### Features
5 |
6 | * add touch and dirty status reaction ([20c435e](https://github.com/xtreamsrl/ngx-validation-errors/commit/20c435eb0e220c97aa1ed44f5a29820086ef30aa))
7 |
8 |
9 |
10 | # [2.0.0](https://github.com/xtreamsrl/ngx-validation-errors/compare/v1.0.0...v2.0.0) (2020-07-05)
11 |
12 |
13 | ### Bug Fixes
14 |
15 | * update pipe creation and usage ([ad000db](https://github.com/xtreamsrl/ngx-validation-errors/commit/ad000db6ae74c1d4c745618b8fd4f01ee0a79ba2))
16 |
17 |
18 | ### chore
19 |
20 | * update readme and package.json ([8adbfab](https://github.com/xtreamsrl/ngx-validation-errors/commit/8adbfabcdbd1f9300d924c364ca7bb0b2cf7cea8))
21 |
22 |
23 | ### Features
24 |
25 | * update project to angular 9 ([f1b6410](https://github.com/xtreamsrl/ngx-validation-errors/commit/f1b641097942e32315662e4105584ba0d875f296))
26 |
27 |
28 | ### BREAKING CHANGES
29 |
30 | * complete update to angular 9
31 |
32 |
33 |
34 | ## 0.4.0 (2020-01-11)
35 |
36 | ### Features
37 |
38 | * add structural directive for controlled errors management
39 | * add standard names for components
40 |
41 | ## 1.0.0 (2020-01-11)
42 |
43 | ### Features
44 |
45 | * update to angular 8
46 | * add structural directive for controlled errors management
47 |
48 | ## Breaking Changes
49 | The 1.0.0 version is compatible with angular 8.
50 |
51 | The components have been renamed according to the angular conventions, now they starts with the library prefix.
52 | Update this
53 | ```angular2html
54 |
60 | ```
61 | changing the name to ngxValidationErrorsField
62 |
63 | ```angular2html
64 |
70 | ```
71 |
72 | The old names are still available bu consider it deprecated!
73 |
74 | ## 0.3.0 (2019-11-19)
75 |
76 | ## Breaking Changes
77 | The 0.3.0 version removes the dependency from @ngx-translate/core to allow using the library
78 | also without this @ngx-translate or with this or other similar libraries
79 |
80 | To update you need to modify the app.module.ts like this:
81 | ```typescript
82 | import {MESSAGES_PIPE_FACTORY_TOKEN, MESSAGES_PROVIDER, NgxValidationErrorsModule} from '@xtream/ngx-validation-errors';
83 |
84 | export function translatePipeFactoryCreator(translateService: TranslateService) {
85 | return (detector: ChangeDetectorRef) => new TranslatePipe(translateService, detector);
86 | }
87 |
88 | @NgModule({
89 | providers: [
90 | {
91 | provide: MESSAGES_PIPE_FACTORY_TOKEN,
92 | useFactory: translatePipeFactoryCreator,
93 | deps: [TranslateService]
94 | },
95 | {
96 | provide: MESSAGES_PROVIDER,
97 | useExisting: TranslateService
98 | }
99 | ]
100 | })
101 |
102 | ```
103 |
104 | The function returns a factory that is used by the library to create a pipe and pass a ChangeDetectorRef instance so on lang change
105 | (or similar event) the components can be updated accordingly.
106 |
107 | If you want to use a custom error mapping without translation you can provide your custom pipe and message provider (that exposes an `instant(key:string):string` method)
108 | like this:
109 |
110 | ```typescript
111 | import {MESSAGES_PIPE_FACTORY_TOKEN, MESSAGES_PROVIDER, NgxValidationErrorsModule} from '@xtream/ngx-validation-errors';
112 |
113 | export function simpleCustomPipeFactoryCreator(messageProvider: SimpleMessagesProviderService) {
114 | return (detector: ChangeDetectorRef) => new SimpleErrorPipe(messageProvider, detector);
115 | }
116 |
117 | @NgModule({
118 | providers: [
119 | {
120 | provide: MESSAGES_PIPE_FACTORY_TOKEN,
121 | useFactory: simpleCustomPipeFactoryCreator,
122 | deps: [SimpleMessagesProviderService]
123 | },
124 | {
125 | provide: MESSAGES_PROVIDER,
126 | useExisting: SimpleMessagesProviderService
127 | }
128 | ]
129 | })
130 | ```
131 |
132 | ### Features
133 |
134 | * remove dependency form @ngx-translate
135 |
136 |
137 | ## 0.2.0 (2019-11-19)
138 |
139 | ### Features
140 |
141 | * add imperative validation clearing
142 |
143 | ## 0.1.0 (2019-11-19)
144 |
145 |
146 | ### Features
147 |
148 | * **array:** add array controls validation
149 |
150 | ## 0.0.4 (2019-10-31)
151 |
152 |
153 | ### Bug Fixes
154 |
155 | * change forRoot method to work with AOT
156 |
157 |
158 | ## 0.0.3 (2019-08-2)
159 |
160 |
161 | ### Bug Fixes
162 |
163 | * change module import for lazy loading error
164 |
165 |
166 | ## 0.0.2 (2019-05-20)
167 |
168 |
169 | ### Bug Fixes
170 |
171 | * add class is-invalid correclty on error 89fb90e
172 | * fallback strategy of error messages 3b5a029
173 | * FormFieldContainer selector in kebab-case 35db7ae
174 |
175 |
176 |
177 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 xtreamsrl
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NgxValidationErrors
2 |
3 | This library allows you to show dynamically created errors in forms.
4 |
5 | Choose the version corresponding to your Angular version:
6 |
7 | Angular | @xtream/ngx-validation-errors
8 | ----------- | -------------------
9 | 7 | 0.x
10 | 8 | 1.x
11 | 9 | 2.x
12 |
13 |
14 | ## Messages generation
15 |
16 | It creates a translation key that follows the following template for each key in the form control errors object
17 |
18 | `${validationContext}.${fieldName}.ERRORS.${errorType}`
19 |
20 | where:
21 | - validationContext is the form identifier (for example _USER.REGISTRATION_ default: "GENERAL")
22 | - fieldName is the form control name in **SCREAMING_SNAKE_CASE**
23 | - errorType is the error key in **SCREAMING_SNAKE_CASE**
24 |
25 | the keys are then translated using a pipe enriching the message using parameters taken from the error object.
26 | if the key is not present in the language file the message fallbacks to `${defaultContext}.ERRORS.${errorType}` (_USER.REGISTRATION.NAME.MINLENGTH_ => _GENERAL.ERRORS.MINLENGTH_)
27 |
28 | ## Install
29 |
30 | `npm i @xtream/ngx-validation-errors`
31 |
32 | ## Usage
33 |
34 |
35 | Import it using
36 | ```typescript
37 | import {NgxValidationErrorsModule} from '@xtream/ngx-validation-errors';
38 |
39 | @NgModule({
40 | imports: [
41 | ...
42 | NgxValidationErrorsModule.forRoot()
43 | ],
44 | providers: [],
45 | bootstrap: [AppComponent]
46 | })
47 | export class AppModule {
48 | }
49 | ```
50 | ### Components with auto errors injection
51 | now you can use validationContext and ngxValidationErrorsField in your template
52 |
53 | ```angular2html
54 |
60 | ```
61 | or
62 | ```angular2html
63 |
69 | ```
70 |
71 | According to the Validators set in the FormControl the errors appear when the input is invalid, dirty and touched.
72 |
73 | ### Structural directive
74 |
75 | The structural directive has been created for special layout library (like material-ui) that have special input/errors
76 | components that do non allow to autoInject errors component. The usage is a little bit more verbose but the you control
77 | errors
78 |
79 | ```angular2html
80 |
86 | ```
87 |
88 | the structural directive needs the form control as parameter (like heroForm.get('name'), if you find a better way to retrieve the inner form control instance please open an issue).
89 | It exposes errors in the template context so you can use them in the ui.
90 |
91 | ### Clearing
92 |
93 | The ValidationContextComponent has an imperative clear that resets all the fields removing all the errors.
94 |
95 | ```typescript
96 | import {ValidationContextComponent} from '@xtream/ngx-validation-errors';
97 |
98 |
99 | @ViewChild(ValidationContextComponent) context: ValidationContextComponent;
100 |
101 |
102 | clearAll() {
103 | this.context.clear()
104 | }
105 | }
106 | ```
107 | ### Configuration
108 |
109 | The library can be configured using the `forRoot` static method
110 |
111 | ```typescript
112 | import {NgxValidationErrorsModule} from '@xtream/ngx-validation-errors';
113 |
114 | @NgModule({
115 | declarations: [
116 | AppComponent,
117 | CustomErrorsComponent
118 | ],
119 | imports: [
120 | ...
121 | NgxValidationErrorsModule.forRoot({
122 | defaultContext: 'CUSTOM_GENERAL',
123 | errorComponent: CustomErrorsComponent
124 | })
125 | ],
126 | providers: [],
127 | entryComponents: [CustomErrorsComponent],
128 | bootstrap: [AppComponent]
129 | })
130 | export class AppModule {
131 | }
132 | ```
133 |
134 | you can set the default validation context and the errorComponent. The last one is instantiated dynamically using
135 | component factory and substituted to the default one, so remember to add it to the entryComponents list.
136 | It must accept 3 inputs:
137 | ```
138 | {
139 | messages: string[];
140 | params: {[key: string]: any};
141 | innerValidation: boolean;
142 | }
143 | ```
144 | ### Message translation
145 |
146 | You can use @ngx-translate providing the translate service and a pipe factory.
147 |
148 | ```typescript
149 | import {MESSAGES_PIPE_FACTORY_TOKEN, MESSAGES_PROVIDER, NgxValidationErrorsModule} from '@xtream/ngx-validation-errors';
150 |
151 | export function translatePipeFactoryCreator(translateService: TranslateService) {
152 | return (detector: ChangeDetectorRef) => new TranslatePipe(translateService, detector);
153 | }
154 |
155 | @NgModule({
156 | providers: [
157 | {
158 | provide: MESSAGES_PIPE_FACTORY_TOKEN,
159 | useFactory: translatePipeFactoryCreator,
160 | deps: [TranslateService]
161 | },
162 | {
163 | provide: MESSAGES_PROVIDER,
164 | useExisting: TranslateService
165 | }
166 | ]
167 | })
168 |
169 | ```
170 |
171 | If you have a custom message mapping you can configure it providing a custom pipe and service.
172 |
173 | ```typescript
174 | import {MESSAGES_PIPE_FACTORY_TOKEN, MESSAGES_PROVIDER, NgxValidationErrorsModule} from '@xtream/ngx-validation-errors';
175 |
176 | export function simpleCustomPipeFactoryCreator(messageProvider: SimpleMessagesProviderService) {
177 | return (detector: ChangeDetectorRef) => new SimpleErrorPipe(messageProvider, detector);
178 | }
179 |
180 | @NgModule({
181 | providers: [
182 | {
183 | provide: MESSAGES_PIPE_FACTORY_TOKEN,
184 | useFactory: simpleCustomPipeFactoryCreator,
185 | deps: [SimpleMessagesProviderService]
186 | },
187 | {
188 | provide: MESSAGES_PROVIDER,
189 | useExisting: SimpleMessagesProviderService
190 | }
191 | ]
192 | })
193 | ```
194 |
195 | # Who we are
196 |
197 | A proudly 🇮🇹 software development and data science startup.
We consider ourselves a family of talented and passionate people building their own products and powerful solutions for our clients. Get to know us more on xtreamers.io or follow us on LinkedIn.
198 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "ngx-validation-errors": {
7 | "projectType": "application",
8 | "schematics": {
9 | "@schematics/angular:component": {
10 | "style": "scss"
11 | }
12 | },
13 | "root": "",
14 | "sourceRoot": "src",
15 | "prefix": "app",
16 | "architect": {
17 | "build": {
18 | "builder": "@angular-devkit/build-angular:browser",
19 | "options": {
20 | "outputPath": "dist/ngx-validation-errors",
21 | "index": "src/index.html",
22 | "main": "src/main.ts",
23 | "polyfills": "src/polyfills.ts",
24 | "tsConfig": "tsconfig.app.json",
25 | "aot": true,
26 | "assets": [
27 | "src/favicon.ico",
28 | "src/assets"
29 | ],
30 | "styles": [
31 | "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
32 | "src/styles.scss"
33 | ],
34 | "scripts": []
35 | },
36 | "configurations": {
37 | "production": {
38 | "fileReplacements": [
39 | {
40 | "replace": "src/environments/environment.ts",
41 | "with": "src/environments/environment.prod.ts"
42 | }
43 | ],
44 | "optimization": true,
45 | "outputHashing": "all",
46 | "sourceMap": false,
47 | "extractCss": true,
48 | "namedChunks": false,
49 | "extractLicenses": true,
50 | "vendorChunk": false,
51 | "buildOptimizer": true,
52 | "budgets": [
53 | {
54 | "type": "initial",
55 | "maximumWarning": "2mb",
56 | "maximumError": "5mb"
57 | },
58 | {
59 | "type": "anyComponentStyle",
60 | "maximumWarning": "6kb",
61 | "maximumError": "10kb"
62 | }
63 | ]
64 | }
65 | }
66 | },
67 | "serve": {
68 | "builder": "@angular-devkit/build-angular:dev-server",
69 | "options": {
70 | "browserTarget": "ngx-validation-errors:build"
71 | },
72 | "configurations": {
73 | "production": {
74 | "browserTarget": "ngx-validation-errors:build:production"
75 | }
76 | }
77 | },
78 | "extract-i18n": {
79 | "builder": "@angular-devkit/build-angular:extract-i18n",
80 | "options": {
81 | "browserTarget": "ngx-validation-errors:build"
82 | }
83 | },
84 | "test": {
85 | "builder": "@angular-devkit/build-angular:karma",
86 | "options": {
87 | "main": "src/test.ts",
88 | "polyfills": "src/polyfills.ts",
89 | "tsConfig": "tsconfig.spec.json",
90 | "karmaConfig": "karma.conf.js",
91 | "assets": [
92 | "src/favicon.ico",
93 | "src/assets"
94 | ],
95 | "styles": [
96 | "src/styles.scss"
97 | ],
98 | "scripts": []
99 | }
100 | },
101 | "lint": {
102 | "builder": "@angular-devkit/build-angular:tslint",
103 | "options": {
104 | "tsConfig": [
105 | "tsconfig.app.json",
106 | "tsconfig.spec.json",
107 | "e2e/tsconfig.json"
108 | ],
109 | "exclude": [
110 | "**/node_modules/**"
111 | ]
112 | }
113 | },
114 | "e2e": {
115 | "builder": "@angular-devkit/build-angular:protractor",
116 | "options": {
117 | "protractorConfig": "e2e/protractor.conf.js",
118 | "devServerTarget": "ngx-validation-errors:serve"
119 | },
120 | "configurations": {
121 | "production": {
122 | "devServerTarget": "ngx-validation-errors:serve:production"
123 | }
124 | }
125 | }
126 | }
127 | },
128 | "@xtream/ngx-validation-errors": {
129 | "projectType": "library",
130 | "root": "projects/xtream/ngx-validation-errors",
131 | "sourceRoot": "projects/xtream/ngx-validation-errors/src",
132 | "prefix": "lib",
133 | "architect": {
134 | "build": {
135 | "builder": "@angular-devkit/build-ng-packagr:build",
136 | "options": {
137 | "tsConfig": "projects/xtream/ngx-validation-errors/tsconfig.lib.json",
138 | "project": "projects/xtream/ngx-validation-errors/ng-package.json"
139 | },
140 | "configurations": {
141 | "production": {
142 | "tsConfig": "projects/xtream/ngx-validation-errors/tsconfig.lib.prod.json"
143 | }
144 | }
145 | },
146 | "test": {
147 | "builder": "@angular-devkit/build-angular:karma",
148 | "options": {
149 | "main": "projects/xtream/ngx-validation-errors/src/test.ts",
150 | "tsConfig": "projects/xtream/ngx-validation-errors/tsconfig.spec.json",
151 | "karmaConfig": "projects/xtream/ngx-validation-errors/karma.conf.js"
152 | }
153 | },
154 | "lint": {
155 | "builder": "@angular-devkit/build-angular:tslint",
156 | "options": {
157 | "tsConfig": [
158 | "projects/xtream/ngx-validation-errors/tsconfig.lib.json",
159 | "projects/xtream/ngx-validation-errors/tsconfig.spec.json"
160 | ],
161 | "exclude": [
162 | "**/node_modules/**"
163 | ]
164 | }
165 | }
166 | }
167 | }},
168 | "defaultProject": "ngx-validation-errors"
169 | }
170 |
--------------------------------------------------------------------------------
/browserslist:
--------------------------------------------------------------------------------
1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 |
5 | # You can see what browsers were selected by your queries by running:
6 | # npx browserslist
7 |
8 | > 0.5%
9 | last 2 versions
10 | Firefox ESR
11 | not dead
12 | not IE 9-11 # For IE 9-11 support, remove 'not'.
--------------------------------------------------------------------------------
/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // @ts-check
2 | // Protractor configuration file, see link for more information
3 | // https://github.com/angular/protractor/blob/master/lib/config.ts
4 |
5 | const { SpecReporter } = require('jasmine-spec-reporter');
6 |
7 | /**
8 | * @type { import("protractor").Config }
9 | */
10 | exports.config = {
11 | allScriptsTimeout: 11000,
12 | specs: [
13 | './src/**/*.e2e-spec.ts'
14 | ],
15 | capabilities: {
16 | browserName: 'chrome'
17 | },
18 | directConnect: true,
19 | baseUrl: 'http://localhost:4200/',
20 | framework: 'jasmine',
21 | jasmineNodeOpts: {
22 | showColors: true,
23 | defaultTimeoutInterval: 30000,
24 | print: function() {}
25 | },
26 | onPrepare() {
27 | require('ts-node').register({
28 | project: require('path').join(__dirname, './tsconfig.json')
29 | });
30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
31 | }
32 | };
--------------------------------------------------------------------------------
/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 | import { browser, logging } from 'protractor';
3 |
4 | describe('workspace-project App', () => {
5 | let page: AppPage;
6 |
7 | beforeEach(() => {
8 | page = new AppPage();
9 | });
10 |
11 | it('should display welcome message', () => {
12 | page.navigateTo();
13 | expect(page.getTitleText()).toEqual('ngx-validation-errors app is running!');
14 | });
15 |
16 | afterEach(async () => {
17 | // Assert that there are no errors emitted from the browser
18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19 | expect(logs).not.toContain(jasmine.objectContaining({
20 | level: logging.Level.SEVERE,
21 | } as logging.Entry));
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo(): Promise {
5 | return browser.get(browser.baseUrl) as Promise;
6 | }
7 |
8 | getTitleText(): Promise {
9 | return element(by.css('app-root .content span')).getText() as Promise;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/e2e/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/e2e",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, './coverage/ngx-validation-errors'),
20 | reports: ['html', 'lcovonly', 'text-summary'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false,
30 | restartOnFileChange: true
31 | });
32 | };
33 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ngx-validation-errors",
3 | "version": "2.1.1",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "test": "ng test",
9 | "lint": "ng lint",
10 | "e2e": "ng e2e",
11 | "build-lib": "npx ng build @xtream/ngx-validation-errors",
12 | "build_lib_prod": "npx ng build @xtream/ngx-validation-errors --prod",
13 | "copy-license": "copy .\\LICENSE .\\dist\\xtream\\ngx-validation-errors",
14 | "copy-readme": "copy .\\README.md .\\dist\\xtream\\ngx-validation-errors",
15 | "copy-files": "npm run copy-license && npm run copy-readme",
16 | "npm_pack": "cd dist/xtream/ngx-validation-errors && npm pack",
17 | "package": "npm run build_lib_prod && npm run copy-files && npm run npm_pack",
18 | "semantic-release": "npx semantic-release"
19 | },
20 | "private": true,
21 | "dependencies": {
22 | "@angular/animations": "~9.1.11",
23 | "@angular/cdk": "~9.2.4",
24 | "@angular/common": "~9.1.11",
25 | "@angular/compiler": "~9.1.11",
26 | "@angular/core": "~9.1.11",
27 | "@angular/forms": "~9.1.11",
28 | "@angular/material": "~9.2.4",
29 | "@angular/platform-browser": "~9.1.11",
30 | "@angular/platform-browser-dynamic": "~9.1.11",
31 | "@angular/router": "~9.1.11",
32 | "@ngx-translate/core": "^12.0.1",
33 | "@ngx-translate/http-loader": "^5.0.0",
34 | "hammerjs": "^2.0.8",
35 | "ngx-bootstrap": "^5.6.0",
36 | "rxjs": "~6.5.4",
37 | "tslib": "^1.10.0",
38 | "zone.js": "~0.10.2"
39 | },
40 | "devDependencies": {
41 | "@angular-devkit/build-angular": "~0.901.10",
42 | "@angular-devkit/build-ng-packagr": "~0.901.10",
43 | "@angular/cli": "~9.1.10",
44 | "@angular/compiler-cli": "~9.1.11",
45 | "@angular/language-service": "^9.1.11",
46 | "@types/jasmine": "~3.5.0",
47 | "@types/jasminewd2": "~2.0.3",
48 | "@types/node": "^12.11.1",
49 | "codelyzer": "^5.1.2",
50 | "conventional-changelog-cli": "^2.0.34",
51 | "jasmine-core": "~3.5.0",
52 | "jasmine-spec-reporter": "~4.2.1",
53 | "karma": "~5.0.0",
54 | "karma-chrome-launcher": "~3.1.0",
55 | "karma-coverage-istanbul-reporter": "~2.1.0",
56 | "karma-jasmine": "~3.0.1",
57 | "karma-jasmine-html-reporter": "^1.4.2",
58 | "ng-packagr": "^9.0.0",
59 | "protractor": "~7.0.0",
60 | "semantic-release": "^17.3.0",
61 | "ts-node": "~8.3.0",
62 | "tslint": "~6.1.0",
63 | "typescript": "~3.8.3"
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/README.md:
--------------------------------------------------------------------------------
1 | # NgxValidationErrors
2 |
3 | This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.11.
4 |
5 | ## Code scaffolding
6 |
7 | Run `ng generate component component-name --project ngx-validation-errors` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ngx-validation-errors`.
8 | > Note: Don't forget to add `--project ngx-validation-errors` or else it will be added to the default project in your `angular.json` file.
9 |
10 | ## Build
11 |
12 | Run `ng build ngx-validation-errors` to build the project. The build artifacts will be stored in the `dist/` directory.
13 |
14 | ## Publishing
15 |
16 | After building your library with `ng build ngx-validation-errors`, go to the dist folder `cd dist/ngx-validation-errors` and run `npm publish`.
17 |
18 | ## Running unit tests
19 |
20 | Run `ng test ngx-validation-errors` to execute the unit tests via [Karma](https://karma-runner.github.io).
21 |
22 | ## Further help
23 |
24 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
25 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, '../../../coverage/xtream/ngx-validation-errors'),
20 | reports: ['html', 'lcovonly', 'text-summary'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false,
30 | restartOnFileChange: true
31 | });
32 | };
33 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/ng-package.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3 | "dest": "../../../dist/xtream/ngx-validation-errors",
4 | "lib": {
5 | "entryFile": "src/public-api.ts"
6 | }
7 | }
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@xtream/ngx-validation-errors",
3 | "author": "Luca Micieli ",
4 | "version": "2.1.1",
5 | "repository": {
6 | "url": "https://github.com/xtreamsrl/ngx-validation-errors"
7 | },
8 | "peerDependencies": {
9 | "@angular/common": "^9.1.11",
10 | "@angular/core": "^9.1.11",
11 | "@angular/forms": "^9.1.11"
12 | },
13 | "dependencies": {
14 | "tslib": "^1.10.0"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/error-validation-config.ts:
--------------------------------------------------------------------------------
1 | import {InjectionToken} from '@angular/core';
2 |
3 | export interface ErrorsComponent {
4 | innerValidationError: boolean;
5 | messages: string[];
6 | params: {[key: string]: any};
7 | }
8 |
9 | export type ValidationErrorsConfig = {
10 | defaultContext?: string;
11 | errorComponent?: ErrorsComponent;
12 | };
13 |
14 | export const VALIDATION_ERROR_CONFIG = new InjectionToken('validationError.config');
15 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/form-array-container.component.ts:
--------------------------------------------------------------------------------
1 | import {
2 | ChangeDetectorRef,
3 | Component,
4 | ComponentFactoryResolver,
5 | ContentChild,
6 | ElementRef,
7 | Inject,
8 | Optional,
9 | Renderer2
10 | } from '@angular/core';
11 | import {FormArrayName} from '@angular/forms';
12 | import {FormValidationContainer} from './form-validation-container';
13 | import {MESSAGES_PROVIDER} from './injection-tokens';
14 | import {VALIDATION_ERROR_CONFIG, ValidationErrorsConfig} from './error-validation-config';
15 | import {Observable} from 'rxjs';
16 |
17 | @Component({
18 | selector: '[ngxValidationErrorsArray], ngx-validation-errors-array, [formArrayContainer], form-array-container',
19 | template: `
20 |
21 |
22 | `
23 | })
24 | export class FormArrayContainerComponent extends FormValidationContainer {
25 |
26 | // tslint:disable-next-line:variable-name
27 | @ContentChild(FormArrayName, {static: true}) _formControl: FormArrayName;
28 |
29 | // tslint:disable-next-line:variable-name
30 | @ContentChild(FormArrayName, {read: ElementRef, static: true}) _el: ElementRef;
31 |
32 | constructor(
33 | // tslint:disable-next-line:variable-name
34 | private _elRef: ElementRef,
35 | // tslint:disable-next-line:variable-name
36 | private _renderer: Renderer2,
37 | // tslint:disable-next-line:variable-name
38 | @Optional() @Inject(MESSAGES_PROVIDER) private _messageProvider: { instant(key: string): string; },
39 | // tslint:disable-next-line:variable-name
40 | private _cdRef: ChangeDetectorRef,
41 | // tslint:disable-next-line:variable-name
42 | private _componentFactoryResolver: ComponentFactoryResolver,
43 | // tslint:disable-next-line:variable-name
44 | @Inject(VALIDATION_ERROR_CONFIG) private _validationErrorsConfig: ValidationErrorsConfig) {
45 | super(_elRef, _renderer, _messageProvider, _cdRef, _componentFactoryResolver, _validationErrorsConfig);
46 | }
47 |
48 | get formControl() {
49 | return this._formControl.control;
50 | }
51 |
52 | get formControlName(): string | number {
53 | return this._formControl.name;
54 | }
55 |
56 | get statusChanges(): Observable {
57 | return this._formControl.control.statusChanges;
58 | }
59 |
60 | get el(): ElementRef {
61 | return this._el;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/form-field-container.component.ts:
--------------------------------------------------------------------------------
1 | import {
2 | ChangeDetectorRef,
3 | Component,
4 | ComponentFactoryResolver,
5 | ContentChild,
6 | ElementRef,
7 | Inject,
8 | Optional,
9 | Renderer2
10 | } from '@angular/core';
11 | import {FormControlName} from '@angular/forms';
12 | import {FormValidationContainer} from './form-validation-container';
13 | import {MESSAGES_PROVIDER} from './injection-tokens';
14 | import {VALIDATION_ERROR_CONFIG, ValidationErrorsConfig} from './error-validation-config';
15 | import {Observable} from 'rxjs';
16 |
17 | @Component({
18 | selector: '[ngxValidationErrorsField], ngx-validation-errors-field, [formFieldContainer], form-field-container',
19 | template: `
20 |
21 |
22 | `
23 | })
24 | export class FormFieldContainerComponent extends FormValidationContainer {
25 |
26 | constructor(
27 | // tslint:disable-next-line:variable-name
28 | private _elRef: ElementRef,
29 | // tslint:disable-next-line:variable-name
30 | private _renderer: Renderer2,
31 | // tslint:disable-next-line:variable-name
32 | @Optional() @Inject(MESSAGES_PROVIDER) private _messageProvider: { instant(key: string): string; },
33 | // tslint:disable-next-line:variable-name
34 | private _cdRef: ChangeDetectorRef,
35 | // tslint:disable-next-line:variable-name
36 | private _componentFactoryResolver: ComponentFactoryResolver,
37 | // tslint:disable-next-line:variable-name
38 | @Inject(VALIDATION_ERROR_CONFIG) private _validationErrorsConfig: ValidationErrorsConfig) {
39 | super(_elRef, _renderer, _messageProvider, _cdRef, _componentFactoryResolver, _validationErrorsConfig);
40 | }
41 |
42 | // tslint:disable-next-line:variable-name
43 | @ContentChild(FormControlName, {static: true}) _formControl: FormControlName;
44 |
45 | // tslint:disable-next-line:variable-name
46 | @ContentChild(FormControlName, {read: ElementRef, static: true}) _input: ElementRef;
47 |
48 | get formControl() {
49 | return this._formControl.control;
50 | }
51 |
52 | get formControlName(): string | number {
53 | return this._formControl.name;
54 | }
55 |
56 | get statusChanges(): Observable {
57 | return this._formControl.control.statusChanges;
58 | }
59 |
60 | get el(): ElementRef {
61 | return this._input;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/form-field-empty-container.directive.ts:
--------------------------------------------------------------------------------
1 | import {Directive, DoCheck, Inject, Input, Optional, Renderer2, TemplateRef, ViewContainerRef} from '@angular/core';
2 | import {AbstractControl, ControlContainer, FormGroup, FormGroupDirective} from '@angular/forms';
3 | import {VALIDATION_ERROR_CONFIG, ValidationErrorsConfig} from './error-validation-config';
4 | import {toScreamingSnakeCase} from './utils';
5 | import {MESSAGES_PROVIDER} from './injection-tokens';
6 |
7 | export class ForFieldErrorsContext {
8 | constructor(public errors: string[]) {
9 | }
10 | }
11 |
12 | @Directive({
13 | selector: '[ngxValidationErrors]',
14 | providers: [
15 | {
16 | provide: ControlContainer,
17 | useExisting: FormGroupDirective
18 | }
19 | ]
20 | })
21 | export class FormFieldEmptyContainerDirective implements DoCheck {
22 |
23 | // tslint:disable-next-line:variable-name
24 | @Input('ngxValidationErrors') formControlRef: AbstractControl;
25 |
26 | @Input() customErrorMessages: {} = {};
27 | @Input() messageParams: {} = {};
28 | @Input() validationDisabled = false;
29 |
30 | rootEl: any;
31 |
32 | public messages: string[];
33 | private validationContext;
34 | private context = {errors: [] as string[]};
35 |
36 | constructor(
37 | private renderer: Renderer2,
38 | private viewContainer: ViewContainerRef,
39 | private template: TemplateRef,
40 | // @Optional() form: FormGroupDirective,
41 | @Optional() @Inject(MESSAGES_PROVIDER) private messageProvider: any,
42 | @Inject(VALIDATION_ERROR_CONFIG) private validationErrorsConfig: ValidationErrorsConfig) {
43 | this.validationContext = validationErrorsConfig.defaultContext;
44 | const nodes = this.viewContainer.createEmbeddedView(this.template, this.context);
45 | this.rootEl = nodes.rootNodes[0];
46 | }
47 |
48 | ngDoCheck(): void {
49 | const hasError = (!this.formControl.valid && this.formControl.touched) && !this.validationDisabled;
50 | let messages;
51 | if (hasError) {
52 | messages = Object.keys(this.formControl.errors || {}).map(error => {
53 | const fieldName = this.formControlName;
54 | const errorKey = `${toScreamingSnakeCase(fieldName)}.ERRORS.${toScreamingSnakeCase(error)}`;
55 | if (this.messageProvider &&
56 | this.messageProvider.instant(`${this.validationContext}.${errorKey}`) === `${this.validationContext}.${errorKey}`) {
57 | return `${this.validationErrorsConfig.defaultContext}.ERRORS.${toScreamingSnakeCase(error)}`;
58 | } else {
59 | return `${this.validationContext}.${errorKey}`;
60 | }
61 | });
62 | const params = Object.values(this.formControl.errors || {}).reduce((a, b) => {
63 | a = {...a, ...b};
64 | return a;
65 | }, {});
66 | this.messageParams = this.messageParams ? {...this.messageParams, ...params} : params;
67 | if (messages && messages.length > 0) {
68 | messages = [messages[0]];
69 | }
70 | }
71 |
72 | if ((messages && !this.messages) || (!messages && this.messages) || (messages && messages[0] !== this.messages[0])) {
73 | this.messages = messages;
74 | this.context.errors = messages;
75 | if (this.rootEl) {
76 | if (messages) {
77 | this.renderer.addClass(this.rootEl, 'has-error');
78 | } else {
79 | this.renderer.removeClass(this.rootEl, 'has-error');
80 | }
81 | }
82 | }
83 | }
84 |
85 | public setValidationContext(context: string): void {
86 | this.validationContext = context;
87 | }
88 |
89 | setInnerValidation(innerValidation: boolean): void {
90 | }
91 |
92 | public clear() {
93 | this.formControl.reset();
94 | this.formControl.setErrors(null);
95 | this.messages = [];
96 | this.context.errors = undefined;
97 | }
98 |
99 | get formControl() {
100 | return this.formControlRef;
101 | }
102 |
103 | get formControlName(): string {
104 | if (this.formControlRef['_parent'] instanceof FormGroup) {
105 | const form = this.formControlRef['_parent'] as FormGroup;
106 | const name = Object.keys(form.controls).find(k => form.controls[k] === this.formControlRef);
107 | return name;
108 | }
109 | return 'field';
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/form-validation-container.ts:
--------------------------------------------------------------------------------
1 | import {
2 | AfterContentInit,
3 | ChangeDetectorRef,
4 | ComponentFactoryResolver,
5 | ComponentRef,
6 | ElementRef,
7 | HostBinding,
8 | Input,
9 | OnDestroy,
10 | Renderer2,
11 | ViewChild,
12 | ViewContainerRef
13 | } from '@angular/core';
14 | import {ValidationErrorsConfig} from './error-validation-config';
15 | import {toScreamingSnakeCase} from './utils';
16 | import {AbstractControl} from '@angular/forms';
17 | import {Observable, Subscription} from 'rxjs';
18 | import {toChangeObservable} from './toChangeObservable';
19 |
20 | export abstract class FormValidationContainer implements AfterContentInit, OnDestroy {
21 |
22 | @Input() customErrorMessages: {} = {};
23 | @Input() messageParams: {} = {};
24 | @Input() validationDisabled = false;
25 | @Input() innerValidationError: boolean;
26 |
27 | @ViewChild('errorsContainer', {read: ViewContainerRef, static: true}) errorsContainer: ViewContainerRef;
28 |
29 | public messages: string[];
30 | private validationContext;
31 | private componentRef: ComponentRef;
32 |
33 | @HostBinding('class.has-error')
34 | public hasErrors: boolean;
35 |
36 | @HostBinding('class.has-success')
37 | public hasSuccess: boolean;
38 |
39 | private subscription: Subscription;
40 |
41 | constructor(
42 | private elRef: ElementRef,
43 | private renderer: Renderer2,
44 | private messageProvider: { instant(key: string): string; },
45 | private cdRef: ChangeDetectorRef,
46 | private componentFactoryResolver: ComponentFactoryResolver,
47 | private validationErrorsConfig: ValidationErrorsConfig) {
48 | this.validationContext = validationErrorsConfig.defaultContext;
49 | }
50 |
51 | ngAfterContentInit(): void {
52 | this.addErrorComponent();
53 | this.subscription = toChangeObservable(this.formControl).subscribe(value => {
54 | this.checkErrors();
55 | this.checkSuccess();
56 | this.updateErrorComponent();
57 | });
58 | }
59 |
60 | ngOnDestroy(): void {
61 | if (this.subscription) {
62 | this.subscription.unsubscribe();
63 | }
64 | }
65 |
66 | addErrorComponent() {
67 | if (this.errorsContainer && !this.componentRef) {
68 | this.errorsContainer.clear();
69 | const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.validationErrorsConfig.errorComponent as any);
70 | this.componentRef = this.errorsContainer.createComponent(componentFactory);
71 | }
72 | }
73 |
74 | updateErrorComponent() {
75 | if (this.componentRef) {
76 | this.componentRef.instance.innerValidationError = this.innerValidationError;
77 | this.componentRef.instance.messages = this.messages;
78 | this.componentRef.instance.params = this.messageParams;
79 | }
80 | }
81 |
82 | checkErrors() {
83 | const hasError = (!this.formControl.valid && this.formControl.dirty && this.formControl.touched) && !this.validationDisabled;
84 | if (hasError && this.el && this.el.nativeElement) {
85 | this.messages = Object.keys(this.formControl.errors || {}).map(error => {
86 | const fieldName = this.formControlName;
87 | const errorKey = `${toScreamingSnakeCase(fieldName + '')}.ERRORS.${toScreamingSnakeCase(error)}`;
88 | if (this.messageProvider &&
89 | this.messageProvider.instant(`${this.validationContext}.${errorKey}`) === `${this.validationContext}.${errorKey}`) {
90 | return `${this.validationErrorsConfig.defaultContext}.ERRORS.${toScreamingSnakeCase(error)}`;
91 | } else {
92 | return `${this.validationContext}.${errorKey}`;
93 | }
94 | });
95 | const params = Object.values(this.formControl.errors || {}).reduce((a, b) => {
96 | a = {...a, ...b};
97 | return a;
98 | }, {});
99 | this.messageParams = this.messageParams ? {...this.messageParams, ...params} : params;
100 | if (this.messages && this.messages.length > 0) {
101 | this.messages = [this.messages[0]];
102 | }
103 | try {
104 | this.renderer.removeClass(this.el.nativeElement, 'is-valid');
105 |
106 | } catch (e) {
107 | }
108 | this.renderer.addClass(this.el.nativeElement, 'is-invalid');
109 |
110 | }
111 |
112 | this.hasErrors = hasError;
113 | }
114 |
115 | checkSuccess(): void {
116 | const hasSuccess = (
117 | this.formControl.valid &&
118 | this.formControl.dirty && this.formControl.touched) &&
119 | !this.validationDisabled;
120 | if (hasSuccess && this.el && this.el.nativeElement) {
121 | this.messages = [];
122 | try {
123 | this.renderer.removeClass(this.el.nativeElement, 'is-invalid');
124 |
125 | } catch (e) {
126 | }
127 | }
128 | this.hasSuccess = hasSuccess;
129 | }
130 |
131 | public setValidationContext(context: string): void {
132 | this.validationContext = context;
133 | }
134 |
135 | setInnerValidation(innerValidation: boolean): void {
136 | this.innerValidationError = innerValidation;
137 | }
138 |
139 | abstract get formControl(): AbstractControl;
140 |
141 | abstract get statusChanges(): Observable;
142 |
143 | abstract get formControlName(): string | number;
144 |
145 | abstract get el(): ElementRef;
146 |
147 | public clear() {
148 | this.formControl.reset();
149 | this.formControl.setErrors(null);
150 | this.renderer.removeClass(this.el.nativeElement, 'is-valid');
151 | this.renderer.removeClass(this.el.nativeElement, 'is-invalid');
152 | this.messages = [];
153 | }
154 |
155 | }
156 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/injection-tokens.ts:
--------------------------------------------------------------------------------
1 | import {InjectionToken} from '@angular/core';
2 |
3 | export const ValidationErrorsConfigObject = new InjectionToken('ValidationErrorsConfigObject');
4 | export const FOR_ROOT_OPTIONS_TOKEN = new InjectionToken('forRootOptionToken');
5 | export const MESSAGES_PROVIDER = new InjectionToken<{ instant(key: string): string; }>('MessagesProvider');
6 | export const MESSAGES_PIPE_FACTORY_TOKEN = new InjectionToken('MessagePipeFactoryToken');
7 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/inner-map-to-message.pipe.ts:
--------------------------------------------------------------------------------
1 | import {Injectable, Pipe, PipeTransform} from '@angular/core';
2 |
3 | @Injectable()
4 | @Pipe({
5 | name: 'innerMapToMessage',
6 | pure: false
7 | })
8 | export class InnerMapToMessagePipe implements PipeTransform {
9 |
10 | transform(value: any, args?: any): any {
11 | return value;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/input-errors.component.scss:
--------------------------------------------------------------------------------
1 | :host {
2 | position: absolute;
3 |
4 | .error-wrapper {
5 | position: relative;
6 | left: 41px;
7 | bottom: 2px;
8 |
9 | span {
10 | font-size: 0.8em;
11 | color: red;
12 | font-weight: 500;
13 | }
14 | }
15 |
16 | }
17 |
18 | :host(.is-inner) {
19 | position: absolute;
20 |
21 | .error-wrapper {
22 | position: relative;
23 | left: 37px;
24 | bottom: 20px;
25 |
26 | span {
27 | font-size: 0.8em;
28 | color: red;
29 | font-weight: 500;
30 | }
31 | }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/input-errors.component.ts:
--------------------------------------------------------------------------------
1 | import {Component, HostBinding, Input} from '@angular/core';
2 | import {AbstractControl, AbstractControlDirective} from '@angular/forms';
3 | import {ErrorsComponent} from './error-validation-config';
4 |
5 | @Component({
6 |
7 | // tslint:disable-next-line:component-selector
8 | selector: 'input-errors',
9 | template: `
10 |
11 | {{ message | mapToMessage: params }}
15 |
16 | `,
17 | styleUrls: ['./input-errors.component.scss']
18 | })
19 | export class InputErrorsComponent implements ErrorsComponent {
20 |
21 | @Input() public messages: string[] = [];
22 | @Input() public params: { [key: string]: any } = {};
23 | @Input() @HostBinding('class.is-inner') public innerValidationError: boolean;
24 |
25 | @Input()
26 | private control: AbstractControlDirective | AbstractControl;
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/map-to-message.pipe.ts:
--------------------------------------------------------------------------------
1 | import {ChangeDetectorRef, Inject, Optional, Pipe, PipeTransform} from '@angular/core';
2 | import {InnerMapToMessagePipe} from './inner-map-to-message.pipe';
3 | import {MESSAGES_PIPE_FACTORY_TOKEN} from './injection-tokens';
4 |
5 | @Pipe({
6 | name: 'mapToMessage',
7 | pure: false
8 | })
9 | export class MapToMessagePipe implements PipeTransform {
10 |
11 | pipe: PipeTransform;
12 |
13 | constructor(
14 | @Optional() cdRef: ChangeDetectorRef,
15 | @Optional() @Inject(MESSAGES_PIPE_FACTORY_TOKEN) private pipeFactory: any
16 | ) {
17 |
18 | if (pipeFactory) {
19 | try {
20 | this.pipe = pipeFactory(cdRef);
21 | } catch (e) {
22 | console.error(e);
23 | this.pipe = new InnerMapToMessagePipe();
24 | }
25 | } else {
26 | this.pipe = new InnerMapToMessagePipe();
27 | }
28 | }
29 |
30 | transform(value: any, ...args: any): any {
31 | return this.pipe.transform(value, ...args);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/ngx-validation-errors.module.ts:
--------------------------------------------------------------------------------
1 | import {FOR_ROOT_OPTIONS_TOKEN, ValidationErrorsConfigObject} from './injection-tokens';
2 | import {ModuleWithProviders, NgModule} from '@angular/core';
3 | import {InputErrorsComponent} from './input-errors.component';
4 | import {FormFieldContainerComponent} from './form-field-container.component';
5 | import {ValidationContextComponent} from './validation-context.component';
6 | import {VALIDATION_ERROR_CONFIG, ValidationErrorsConfig} from './error-validation-config';
7 | import {CommonModule} from '@angular/common';
8 | import {FormsModule, ReactiveFormsModule} from '@angular/forms';
9 | import {FormArrayContainerComponent} from './form-array-container.component';
10 | import {MapToMessagePipe} from './map-to-message.pipe';
11 | import {InnerMapToMessagePipe} from './inner-map-to-message.pipe';
12 | import {FormFieldEmptyContainerDirective} from './form-field-empty-container.directive';
13 |
14 |
15 | export const defaultConfig = {
16 | defaultContext: 'GENERAL',
17 | errorComponent: InputErrorsComponent as any
18 | } as ValidationErrorsConfig;
19 |
20 | export function configFactory(customConfig: ValidationErrorsConfig, currentConfig: ValidationErrorsConfig) {
21 | const actualConfig = {...currentConfig};
22 | if (customConfig) {
23 | if (customConfig.defaultContext) {
24 | actualConfig.defaultContext = customConfig.defaultContext;
25 | }
26 |
27 | if (customConfig.errorComponent) {
28 | actualConfig.errorComponent = customConfig.errorComponent;
29 | }
30 | }
31 | return actualConfig;
32 | }
33 |
34 | @NgModule({
35 | declarations: [
36 | InputErrorsComponent,
37 | FormFieldContainerComponent,
38 | FormFieldEmptyContainerDirective,
39 | FormArrayContainerComponent,
40 | ValidationContextComponent,
41 | MapToMessagePipe,
42 | InnerMapToMessagePipe
43 | ],
44 | imports: [
45 | CommonModule,
46 | FormsModule,
47 | ReactiveFormsModule
48 | ],
49 | exports: [
50 | InputErrorsComponent,
51 | FormFieldContainerComponent,
52 | FormArrayContainerComponent,
53 | ValidationContextComponent,
54 | FormFieldEmptyContainerDirective
55 | ],
56 | entryComponents: [
57 | InputErrorsComponent
58 | ]
59 | })
60 | export class NgxValidationErrorsModule {
61 |
62 | static forRoot(config?: ValidationErrorsConfig): ModuleWithProviders {
63 | return {
64 | ngModule: NgxValidationErrorsModule,
65 | providers: [
66 | {
67 | provide: ValidationErrorsConfigObject, useValue: defaultConfig as ValidationErrorsConfig
68 | },
69 | {
70 | provide: FOR_ROOT_OPTIONS_TOKEN,
71 | useValue: config
72 | },
73 | MapToMessagePipe,
74 | {
75 | provide: VALIDATION_ERROR_CONFIG,
76 | useFactory: configFactory,
77 | deps: [FOR_ROOT_OPTIONS_TOKEN, ValidationErrorsConfigObject]
78 | },
79 | MapToMessagePipe,
80 | InnerMapToMessagePipe
81 | ]
82 | };
83 | }
84 | }
85 |
86 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/toChangeObservable.ts:
--------------------------------------------------------------------------------
1 | import {AbstractControl} from '@angular/forms';
2 | import {merge, Observable, Subject} from 'rxjs';
3 | import {debounceTime, mergeAll, tap} from 'rxjs/operators';
4 |
5 | function wrapMethod(subject$: Subject, name: string, control: AbstractControl) {
6 |
7 | const prevMethod = control[name];
8 |
9 | function wrappedMethod(...args: any) {
10 | prevMethod.bind(control)(...args);
11 | subject$.next();
12 | }
13 |
14 | control[name] = wrappedMethod;
15 | }
16 |
17 | export function toChangeObservable(control: AbstractControl): Observable {
18 |
19 | const touchedChanges$ = new Subject();
20 |
21 | wrapMethod(touchedChanges$, 'markAsTouched', control);
22 | wrapMethod(touchedChanges$, 'markAsUntouched', control);
23 | wrapMethod(touchedChanges$, 'markAsDirty', control);
24 | wrapMethod(touchedChanges$, 'markAsPristine', control);
25 |
26 | const obs = merge(touchedChanges$, control.statusChanges);
27 |
28 | return obs.pipe(
29 | debounceTime(100)
30 | );
31 | }
32 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/utils.ts:
--------------------------------------------------------------------------------
1 | export function toScreamingSnakeCase(input: string): string {
2 | return input.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase();
3 | }
4 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/lib/validation-context.component.ts:
--------------------------------------------------------------------------------
1 | import {AfterContentInit, ChangeDetectorRef, Component, ContentChildren, Input, QueryList} from '@angular/core';
2 | import {FormFieldContainerComponent} from './form-field-container.component';
3 | import {FormArrayContainerComponent} from './form-array-container.component';
4 | import {FormFieldEmptyContainerDirective} from './form-field-empty-container.directive';
5 |
6 | @Component({
7 | // tslint:disable:component-selector
8 | selector: '[validationContext]',
9 | template: ''
10 | })
11 | export class ValidationContextComponent implements AfterContentInit {
12 |
13 | @ContentChildren(FormFieldContainerComponent, {descendants: true}) fieldValidators: QueryList;
14 | @ContentChildren(FormArrayContainerComponent, {descendants: true}) arrayValidators: QueryList;
15 | @ContentChildren(FormFieldEmptyContainerDirective, {descendants: true}) directives: QueryList;
16 |
17 | // tslint:disable:no-input-rename
18 | @Input() validationContext: string;
19 | @Input() innerValidationError: boolean;
20 |
21 |
22 | constructor(private cdRef: ChangeDetectorRef) {
23 | }
24 |
25 | ngAfterContentInit(): void {
26 | if (this.fieldValidators) {
27 | this.fieldValidators.forEach(i => {
28 | i.setValidationContext(this.validationContext);
29 | i.setInnerValidation(this.innerValidationError);
30 | });
31 | }
32 | if (this.arrayValidators) {
33 | this.arrayValidators.forEach(i => {
34 | i.setValidationContext(this.validationContext);
35 | i.setInnerValidation(this.innerValidationError);
36 | });
37 | }
38 | if (this.directives) {
39 | this.directives.forEach(i => {
40 | i.setValidationContext(this.validationContext);
41 | i.setInnerValidation(this.innerValidationError);
42 | });
43 | }
44 | }
45 |
46 | public clear(): void {
47 |
48 | if (this.fieldValidators) {
49 | this.fieldValidators.forEach(v => {
50 | v.clear();
51 | });
52 | }
53 |
54 | if (this.arrayValidators) {
55 | this.arrayValidators.forEach(v => {
56 | v.clear();
57 | });
58 | }
59 | if (this.directives) {
60 | this.directives.forEach(v => {
61 | v.clear();
62 | });
63 | }
64 | this.cdRef.markForCheck();
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/public-api.ts:
--------------------------------------------------------------------------------
1 | export {NgxValidationErrorsModule} from './lib/ngx-validation-errors.module';
2 | export {ValidationContextComponent} from './lib/validation-context.component';
3 | export {InputErrorsComponent} from './lib/input-errors.component';
4 | export {FormFieldContainerComponent} from './lib/form-field-container.component';
5 | export {FormArrayContainerComponent} from './lib/form-array-container.component';
6 | export {FormFieldEmptyContainerDirective, ForFieldErrorsContext} from './lib/form-field-empty-container.directive';
7 | export {MESSAGES_PIPE_FACTORY_TOKEN} from './lib/injection-tokens';
8 | export {MESSAGES_PROVIDER} from './lib/injection-tokens';
9 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'core-js/es7/reflect';
4 | import 'zone.js/dist/zone';
5 | import 'zone.js/dist/zone-testing';
6 | import { getTestBed } from '@angular/core/testing';
7 | import {
8 | BrowserDynamicTestingModule,
9 | platformBrowserDynamicTesting
10 | } from '@angular/platform-browser-dynamic/testing';
11 |
12 | declare const require: any;
13 |
14 | // First, initialize the Angular testing environment.
15 | getTestBed().initTestEnvironment(
16 | BrowserDynamicTestingModule,
17 | platformBrowserDynamicTesting()
18 | );
19 | // Then we find all the tests.
20 | const context = require.context('./', true, /\.spec\.ts$/);
21 | // And load the modules.
22 | context.keys().map(context);
23 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/tsconfig.lib.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../../out-tsc/lib",
5 | "target": "es2015",
6 | "declaration": true,
7 | "inlineSources": true,
8 | "types": [],
9 | "lib": [
10 | "dom",
11 | "es2018"
12 | ]
13 | },
14 | "angularComplerOptions": {
15 | "skipTemplateCodegen": true,
16 | "strictMetadataEmit": true,
17 | "enableResourceInlining": true
18 | },
19 | "exclude": [
20 | "src/test.ts",
21 | "**/*.spec.ts"
22 | ]
23 | }
24 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/tsconfig.lib.prod.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.lib.json",
3 | "angularCompilerOptions": {
4 | "enableIvy": false
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../../../out-tsc/spec",
5 | "types": [
6 | "jasmine",
7 | "node"
8 | ]
9 | },
10 | "files": [
11 | "src/test.ts"
12 | ],
13 | "include": [
14 | "**/*.spec.ts",
15 | "**/*.d.ts"
16 | ]
17 | }
18 |
--------------------------------------------------------------------------------
/projects/xtream/ngx-validation-errors/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../../tslint.json",
3 | "rules": {
4 | "directive-selector": [
5 | true,
6 | "attribute",
7 | "ngxValidationErrors",
8 | "camelCase"
9 | ],
10 | "component-selector": [
11 | true,
12 | "element",
13 | "ngx-validation-errors",
14 | "kebab-case"
15 | ]
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import {NgModule} from '@angular/core';
2 | import {RouterModule, Routes} from '@angular/router';
3 | import {MainFromComponent} from './main-from/main-from.component';
4 | import {MaterialFromComponent} from './material-from/material-from.component';
5 |
6 | const routes: Routes = [
7 | {
8 | path: 'not-lazy',
9 | component: MainFromComponent
10 | },
11 | {
12 | path: 'material',
13 | component: MaterialFromComponent
14 | },
15 | {
16 | path: 'lazy',
17 | loadChildren: () => import('./lazy/lazy.module').then(res => res.LazyModule)
18 | },
19 | {
20 | path: '',
21 | pathMatch: 'full',
22 | redirectTo: 'lazy'
23 | }
24 | ];
25 |
26 | @NgModule({
27 | imports: [RouterModule.forRoot(routes)],
28 | exports: [RouterModule]
29 | })
30 | export class AppRoutingModule {
31 | }
32 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/app/app.component.scss:
--------------------------------------------------------------------------------
1 |
2 | .input-wrapper {
3 | position: relative;
4 | padding-bottom: 20px;
5 | }
6 |
7 | form {
8 | width: 50%;
9 | margin: auto;
10 | }
11 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import {Component, OnInit} from '@angular/core';
2 | import {FormControl, FormGroup, Validators} from '@angular/forms';
3 | import {TranslateService} from '@ngx-translate/core';
4 |
5 | @Component({
6 | selector: 'app-root',
7 | templateUrl: './app.component.html',
8 | styleUrls: ['./app.component.scss']
9 | })
10 | export class AppComponent implements OnInit {
11 |
12 | heroForm: FormGroup;
13 |
14 | constructor(private translateService: TranslateService) {
15 | this.heroForm = new FormGroup({
16 | name: new FormControl(null, [Validators.required, Validators.minLength(4)]),
17 | surname: new FormControl(null, [Validators.required, Validators.maxLength(1000)])
18 | });
19 | }
20 |
21 | ngOnInit(): void {
22 | this.translateService.setDefaultLang('en');
23 | this.translateService.use('en');
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import {BrowserModule, HammerModule} from '@angular/platform-browser';
2 | import {ChangeDetectorRef, NgModule} from '@angular/core';
3 |
4 | import {AppRoutingModule} from './app-routing.module';
5 | import {AppComponent} from './app.component';
6 | import {MESSAGES_PIPE_FACTORY_TOKEN, MESSAGES_PROVIDER, NgxValidationErrorsModule} from '@xtream/ngx-validation-errors';
7 | import {TranslateLoader, TranslateModule, TranslatePipe, TranslateService} from '@ngx-translate/core';
8 | import {TranslateHttpLoader} from '@ngx-translate/http-loader';
9 | import {HttpClient, HttpClientModule} from '@angular/common/http';
10 | import {FormsModule, ReactiveFormsModule} from '@angular/forms';
11 | import {CustomErrorsComponent} from './custom-errors/custom-errors.component';
12 | import {MainFromComponent} from './main-from/main-from.component';
13 | import {SharedModule} from './shared/shared.module';
14 | import {SimpleErrorPipe} from './simple-error-pipe.pipe';
15 | import {SimpleMessagesProviderService} from './simple-messages-provider.service';
16 | import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
17 | import {MatInputModule} from '@angular/material/input';
18 | import {MatButtonModule} from '@angular/material/button';
19 | import {MaterialFromComponent} from './material-from/material-from.component';
20 |
21 | export function httpLoaderFactory(http: HttpClient): TranslateLoader {
22 | return new TranslateHttpLoader(http, '/assets/i18n/', '.json');
23 | }
24 |
25 |
26 | export function translatePipeFactoryCreator(translateService: TranslateService) {
27 | return (detector: ChangeDetectorRef) => new TranslatePipe(translateService, detector);
28 | }
29 |
30 |
31 | export function simpleCustomPipeFactoryCreator(messageProvider: SimpleMessagesProviderService) {
32 | return (detector: ChangeDetectorRef) => new SimpleErrorPipe(messageProvider, detector);
33 | }
34 |
35 | @NgModule({
36 | declarations: [
37 | AppComponent,
38 | CustomErrorsComponent,
39 | MainFromComponent,
40 | MaterialFromComponent,
41 | SimpleErrorPipe
42 | ],
43 | imports: [
44 | AppRoutingModule,
45 | HttpClientModule,
46 | HammerModule,
47 | BrowserModule,
48 | SharedModule,
49 | FormsModule,
50 | ReactiveFormsModule,
51 | NgxValidationErrorsModule.forRoot(),
52 | TranslateModule.forRoot({
53 | loader: {
54 | provide: TranslateLoader,
55 | useFactory: httpLoaderFactory,
56 | deps: [HttpClient]
57 | }
58 | }),
59 | MatInputModule,
60 | MatButtonModule,
61 | BrowserAnimationsModule,
62 | ],
63 | providers: [
64 |
65 | {
66 | provide: MESSAGES_PIPE_FACTORY_TOKEN,
67 | useFactory: translatePipeFactoryCreator,
68 | deps: [TranslateService]
69 | },
70 | {
71 | provide: MESSAGES_PROVIDER,
72 | useExisting: SimpleMessagesProviderService
73 | }
74 | ],
75 | entryComponents: [CustomErrorsComponent],
76 | bootstrap: [
77 | AppComponent
78 | ]
79 | })
80 | export class AppModule {
81 | }
82 |
--------------------------------------------------------------------------------
/src/app/custom-errors/custom-errors.component.html:
--------------------------------------------------------------------------------
1 |
2 | 0">{{messages}}
3 |
4 |
--------------------------------------------------------------------------------
/src/app/custom-errors/custom-errors.component.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/custom-errors/custom-errors.component.ts:
--------------------------------------------------------------------------------
1 | import {Component, HostBinding, Input, OnInit, TemplateRef, ViewChild, ViewContainerRef} from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-custom-errors',
5 | templateUrl: './custom-errors.component.html',
6 | styleUrls: ['./custom-errors.component.scss']
7 | })
8 | export class CustomErrorsComponent implements OnInit {
9 |
10 | @Input() public messages: string[] = [];
11 | @Input() public params: {[key: string]: any} = {};
12 | @Input() @HostBinding('class.is-inner') public innerValidationError: boolean;
13 |
14 | @ViewChild('impl', {static: true}) template: TemplateRef;
15 |
16 | constructor(private vcr: ViewContainerRef) {
17 | }
18 |
19 | ngOnInit() {
20 | this.vcr.createEmbeddedView(this.template);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/app/errors-mapping.ts:
--------------------------------------------------------------------------------
1 | export const ERRORS = {
2 | 'GENERAL.ERRORS.MINLENGTH': 'IL campo deve essere almeno di x caratteri',
3 | 'GENERAL.ERRORS.REQUIRED': 'Campo obblogatorio',
4 | };
5 |
--------------------------------------------------------------------------------
/src/app/lazy/lazy-form/lazy-form.component.css:
--------------------------------------------------------------------------------
1 |
2 | .input-wrapper {
3 | position: relative;
4 | padding-bottom: 20px;
5 | }
6 |
7 | form {
8 | width: 50%;
9 | margin: auto;
10 | }
11 |
--------------------------------------------------------------------------------
/src/app/lazy/lazy-form/lazy-form.component.html:
--------------------------------------------------------------------------------
1 |
2 |

3 |
4 | xtream validation errors lazy
5 |
6 |
7 |
8 |
9 |
31 |
32 |
33 |
45 |
46 |
--------------------------------------------------------------------------------
/src/app/lazy/lazy-form/lazy-form.component.ts:
--------------------------------------------------------------------------------
1 | import {Component, OnInit, ViewChild} from '@angular/core';
2 | import {AbstractControl, FormArray, FormControl, FormGroup, Validators} from '@angular/forms';
3 | import {TranslateService} from '@ngx-translate/core';
4 | import {ValidationContextComponent} from '@xtream/ngx-validation-errors';
5 | import {distinctUntilChanged, tap} from 'rxjs/operators';
6 |
7 | function minCheckSelected(size: number) {
8 | return (control: AbstractControl) => {
9 | const values = control.value as (boolean | undefined)[];
10 | const selected = values.filter(v => !!v).length;
11 | if (selected < size) {
12 | return {checkBoxes: true};
13 | }
14 | return null;
15 | };
16 | }
17 |
18 | @Component({
19 | selector: 'app-lazy-form',
20 | templateUrl: './lazy-form.component.html',
21 | styleUrls: ['./lazy-form.component.css']
22 | })
23 | export class LazyFormComponent implements OnInit {
24 |
25 | @ViewChild('firstForm', {
26 | read: ValidationContextComponent,
27 | static: true
28 | }) validationContext: ValidationContextComponent;
29 |
30 | heroForm: FormGroup;
31 |
32 | boxesInfo = [
33 | 'a',
34 | 'b',
35 | 'c',
36 | 'd'
37 | ];
38 |
39 | constructor(private translateService: TranslateService) {
40 | this.heroForm = new FormGroup({
41 | name: new FormControl(null, [Validators.required, Validators.minLength(4)]),
42 | surname: new FormControl({value: null, disabled: true}, [Validators.required, Validators.maxLength(1000)]),
43 | checkBoxes: new FormArray(this.boxesInfo.map(a => new FormControl()), [minCheckSelected(1)])
44 | });
45 |
46 | this.heroForm.valueChanges.pipe(
47 | distinctUntilChanged(),
48 | tap(v => {
49 | console.debug('v', v);
50 | if (v.name) {
51 | this.heroForm.controls['surname'].enable({emitEvent: false});
52 | } else {
53 | this.heroForm.controls['surname'].disable({emitEvent: false});
54 | }
55 | })
56 | ).subscribe()
57 | }
58 |
59 | ngOnInit(): void {
60 | this.translateService.setDefaultLang('en');
61 | this.translateService.use('en');
62 | }
63 |
64 | clearForm() {
65 | console.debug('this.validationContext', this.validationContext);
66 | this.validationContext.clear();
67 |
68 | }
69 |
70 | chooseLanguage(lan: string) {
71 | this.translateService.use(lan);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/app/lazy/lazy-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 | import {LazyFormComponent} from './lazy-form/lazy-form.component';
4 |
5 | const routes: Routes = [
6 | {
7 | path:'',
8 | component: LazyFormComponent
9 | }
10 | ];
11 |
12 | @NgModule({
13 | imports: [RouterModule.forChild(routes)],
14 | exports: [RouterModule]
15 | })
16 | export class AppRoutingModule { }
17 |
--------------------------------------------------------------------------------
/src/app/lazy/lazy.module.ts:
--------------------------------------------------------------------------------
1 | import {NgModule} from '@angular/core';
2 | import {LazyFormComponent} from './lazy-form/lazy-form.component';
3 | import {AppRoutingModule} from './lazy-routing.module';
4 | import {ReactiveFormsModule} from '@angular/forms';
5 | import {SharedModule} from '../shared/shared.module';
6 |
7 | @NgModule({
8 | imports: [
9 | AppRoutingModule,
10 | ReactiveFormsModule,
11 | SharedModule,
12 | ],
13 | declarations: [LazyFormComponent]
14 | })
15 | export class LazyModule {
16 | }
17 |
--------------------------------------------------------------------------------
/src/app/main-from/main-from.component.css:
--------------------------------------------------------------------------------
1 |
2 | .input-wrapper {
3 | position: relative;
4 | padding-bottom: 20px;
5 | }
6 |
7 | form {
8 | width: 50%;
9 | margin: auto;
10 | }
11 |
--------------------------------------------------------------------------------
/src/app/main-from/main-from.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |

4 |
5 | xtream validation errors
6 |
19 |
20 |
21 |
33 |
34 |
--------------------------------------------------------------------------------
/src/app/main-from/main-from.component.ts:
--------------------------------------------------------------------------------
1 | import {Component, OnInit, ViewChild} from '@angular/core';
2 | import {FormControl, FormGroup, Validators} from '@angular/forms';
3 | import {TranslateService} from '@ngx-translate/core';
4 | import {ValidationContextComponent} from '@xtream/ngx-validation-errors';
5 |
6 | @Component({
7 | selector: 'app-main-from',
8 | templateUrl: './main-from.component.html',
9 | styleUrls: ['./main-from.component.css']
10 | })
11 | export class MainFromComponent implements OnInit {
12 |
13 | heroForm: FormGroup;
14 | @ViewChild('firstForm', {read: ValidationContextComponent, static: true}) validationContext: ValidationContextComponent;
15 |
16 | constructor(private translateService: TranslateService) {
17 | this.heroForm = new FormGroup({
18 | name: new FormControl(null, [Validators.required, Validators.minLength(4)]),
19 | surname: new FormControl(null, [Validators.required, Validators.maxLength(1000)])
20 | });
21 | }
22 |
23 | ngOnInit(): void {
24 | this.translateService.setDefaultLang('en');
25 | this.translateService.use('en');
26 | }
27 |
28 | reset(): void {
29 | this.validationContext.clear();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/app/material-from/material-from.component.css:
--------------------------------------------------------------------------------
1 |
2 | .input-wrapper {
3 | position: relative;
4 | padding-bottom: 20px;
5 | }
6 |
7 | form {
8 | width: 50%;
9 | margin: auto;
10 | }
11 |
--------------------------------------------------------------------------------
/src/app/material-from/material-from.component.html:
--------------------------------------------------------------------------------
1 |
2 |

3 |
4 | xtream validation errors
5 |
26 |
27 |
45 |
--------------------------------------------------------------------------------
/src/app/material-from/material-from.component.ts:
--------------------------------------------------------------------------------
1 | import {Component, OnInit, ViewChild} from '@angular/core';
2 | import {FormControl, FormGroup, Validators} from '@angular/forms';
3 | import {TranslateService} from '@ngx-translate/core';
4 | import {ValidationContextComponent} from '@xtream/ngx-validation-errors';
5 |
6 | @Component({
7 | selector: 'app-material-from',
8 | templateUrl: './material-from.component.html',
9 | styleUrls: ['./material-from.component.css']
10 | })
11 | export class MaterialFromComponent implements OnInit {
12 |
13 | heroForm: FormGroup;
14 | @ViewChild('firstForm', {read: ValidationContextComponent, static: true}) validationContext: ValidationContextComponent;
15 |
16 | constructor(private translateService: TranslateService) {
17 | this.heroForm = new FormGroup({
18 | name: new FormControl(null, [Validators.required, Validators.minLength(4)]),
19 | surname: new FormControl(null, [Validators.required, Validators.maxLength(1000)])
20 | });
21 | }
22 |
23 | ngOnInit(): void {
24 | this.translateService.setDefaultLang('en');
25 | this.translateService.use('en');
26 | }
27 |
28 | clearForm() {
29 | console.debug('this.validationContext', this.validationContext);
30 | this.validationContext.clear();
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/app/shared/form-submit.directive.ts:
--------------------------------------------------------------------------------
1 | import {Directive, HostListener, Input} from '@angular/core';
2 | import {FormArray, FormGroup} from '@angular/forms';
3 |
4 | @Directive({
5 | selector: '[appFormSubmit]'
6 | })
7 | export class FormSubmitDirective {
8 |
9 | @Input()
10 | private appFormSubmit: FormGroup;
11 |
12 | constructor() {
13 | }
14 |
15 | @HostListener('submit', ['$event'])
16 | onSubmit(event: Event) {
17 | this.markControlsDirty(this.appFormSubmit);
18 | }
19 |
20 | private markControlsDirty(group: FormGroup | FormArray): void {
21 | Object.keys(group.controls).forEach((key: string) => {
22 | const abstractControl = group.controls[key];
23 |
24 | if (abstractControl instanceof FormGroup || abstractControl instanceof FormArray) {
25 | this.markControlsDirty(abstractControl);
26 | } else {
27 | abstractControl.markAsDirty();
28 | abstractControl.markAsTouched();
29 | abstractControl.updateValueAndValidity();
30 | }
31 | });
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/app/shared/shared.module.ts:
--------------------------------------------------------------------------------
1 | import {NgModule} from '@angular/core';
2 | import {CommonModule} from '@angular/common';
3 | import {TranslateModule} from '@ngx-translate/core';
4 | import {NgxValidationErrorsModule} from '@xtream/ngx-validation-errors';
5 | import {FormSubmitDirective} from './form-submit.directive';
6 |
7 | @NgModule({
8 | declarations: [
9 | FormSubmitDirective
10 | ],
11 | imports: [
12 | NgxValidationErrorsModule
13 | ],
14 | exports: [
15 | TranslateModule,
16 | NgxValidationErrorsModule,
17 | CommonModule,
18 | FormSubmitDirective
19 | ]
20 | })
21 | export class SharedModule {
22 | }
23 |
--------------------------------------------------------------------------------
/src/app/simple-error-pipe.pipe.ts:
--------------------------------------------------------------------------------
1 | import {ChangeDetectorRef, Pipe, PipeTransform} from '@angular/core';
2 | import {SimpleMessagesProviderService} from './simple-messages-provider.service';
3 |
4 | @Pipe({
5 | name: 'simpleError'
6 | })
7 | export class SimpleErrorPipe implements PipeTransform {
8 |
9 | constructor(private messageProvider: SimpleMessagesProviderService, cdRef: ChangeDetectorRef) {
10 | }
11 |
12 | transform(value: any, args?: any): any {
13 | return this.messageProvider.instant(value);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/app/simple-messages-provider.service.ts:
--------------------------------------------------------------------------------
1 | import {Injectable} from '@angular/core';
2 | import {ERRORS} from './errors-mapping';
3 |
4 | @Injectable({
5 | providedIn: 'root'
6 | })
7 | export class SimpleMessagesProviderService {
8 |
9 | constructor() {
10 | }
11 |
12 | public instant(key: string) {
13 | if (key in ERRORS) {
14 | return ERRORS[key];
15 | } else {
16 | return key;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/i18n/en.json:
--------------------------------------------------------------------------------
1 | {
2 | "HOME": {
3 | "TITLE": "Validation erorrs example"
4 | },
5 | "GENERAL": {
6 | "ERRORS": {
7 | "MINLENGTH": "The field it too short. You need ti insert at least {{requiredLength}}",
8 | "REQUIRED" : "The field is required"
9 | }
10 | },
11 | "NEW_HERO": {
12 | "NAME": {
13 | "ERRORS": {
14 | "MINLENGTH" : "The hero name must be at least {{requiredLength}} characters",
15 | "REQUIRED" : "The hero name is required"
16 | }
17 | }
18 | },
19 | "USER": {
20 | "REGISTRATION": {
21 | "ERRORS": {
22 | "MINLENGTH": "Name must be at least {{minlength.requiredLength}}"
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/assets/i18n/it.json:
--------------------------------------------------------------------------------
1 | {
2 | "HOME": {
3 | "TITLE": "Validation erorrs example"
4 | },
5 | "GENERAL": {
6 | "ERRORS": {
7 | "MINLENGTH": "Questo campo è troppo corto. Deve essere almeno di {{requiredLength}}",
8 | "REQUIRED" : "Questo campo è obbligatorio"
9 | }
10 | },
11 | "NEW_HERO": {
12 | "NAME": {
13 | "ERRORS": {
14 | "MINLENGTH" : "Il nome dell'eroe deve essere almeno di {{requiredLength}} caratteri",
15 | "REQUIRED" : "Il nome dell'eroe è obbligatorio"
16 | }
17 | }
18 | },
19 | "USER": {
20 | "REGISTRATION": {
21 | "ERRORS": {
22 | "MINLENGTH": "Il nome deve essere almeno di {{minlength.requiredLength}}"
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/assets/images/logo-blu.svg:
--------------------------------------------------------------------------------
1 |
31 |
--------------------------------------------------------------------------------
/src/assets/images/logo-white.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false
7 | };
8 |
9 | /*
10 | * For easier debugging in development mode, you can import the following file
11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
12 | *
13 | * This import should be commented out in production mode because it will have a negative impact
14 | * on performance if an error is thrown.
15 | */
16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
17 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xtreamsrl/ngx-validation-errors/HEAD/src/favicon.ico
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NgxValidationErrors
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import 'hammerjs';
2 | import { enableProdMode } from '@angular/core';
3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
4 |
5 | import { AppModule } from './app/app.module';
6 | import { environment } from './environments/environment';
7 |
8 | if (environment.production) {
9 | enableProdMode();
10 | }
11 |
12 | platformBrowserDynamic().bootstrapModule(AppModule)
13 | .catch(err => console.error(err));
14 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
22 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
23 |
24 | /**
25 | * Web Animations `@angular/platform-browser/animations`
26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
28 | */
29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
30 |
31 | /**
32 | * By default, zone.js will patch all possible macroTask and DomEvents
33 | * user can disable parts of macroTask/DomEvents patch by setting following flags
34 | * because those flags need to be set before `zone.js` being loaded, and webpack
35 | * will put import in the top of bundle, so user need to create a separate file
36 | * in this directory (for example: zone-flags.ts), and put the following flags
37 | * into that file, and then add the following code before importing zone.js.
38 | * import './zone-flags';
39 | *
40 | * The flags allowed in zone-flags.ts are listed here.
41 | *
42 | * The following flags will work for all browsers.
43 | *
44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
47 | *
48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
50 | *
51 | * (window as any).__Zone_enable_cross_context_check = true;
52 | *
53 | */
54 |
55 | /***************************************************************************************************
56 | * Zone JS is required by default for Angular itself.
57 | */
58 | import 'zone.js/dist/zone'; // Included with Angular CLI.
59 |
60 |
61 | /***************************************************************************************************
62 | * APPLICATION IMPORTS
63 | */
64 |
--------------------------------------------------------------------------------
/src/styles.scss:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
3 |
4 |
5 | html, body { height: 100%; }
6 | body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
7 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/zone-testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: {
11 | context(path: string, deep?: boolean, filter?: RegExp): {
12 | keys(): string[];
13 | (id: string): T;
14 | };
15 | };
16 |
17 | // First, initialize the Angular testing environment.
18 | getTestBed().initTestEnvironment(
19 | BrowserDynamicTestingModule,
20 | platformBrowserDynamicTesting()
21 | );
22 | // Then we find all the tests.
23 | const context = require.context('./', true, /\.spec\.ts$/);
24 | // And load the modules.
25 | context.keys().map(context);
26 |
--------------------------------------------------------------------------------
/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "./out-tsc/app",
5 | "types": []
6 | },
7 | "files": [
8 | "src/main.ts",
9 | "src/polyfills.ts"
10 | ],
11 | "include": [
12 | "src/**/*.d.ts"
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "baseUrl": "./",
5 | "outDir": "./dist/out-tsc",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "downlevelIteration": true,
9 | "experimentalDecorators": true,
10 | "module": "esnext",
11 | "moduleResolution": "node",
12 | "importHelpers": true,
13 | "target": "es2015",
14 | "lib": [
15 | "es2018",
16 | "dom"
17 | ],
18 | "paths": {
19 | "@xtream/ngx-validation-errors": [
20 | "dist/xtream/ngx-validation-errors/xtream-ngx-validation-errors",
21 | "dist/xtream/ngx-validation-errors"
22 | ]
23 | }
24 | },
25 | "angularCompilerOptions": {
26 | "fullTemplateTypeCheck": true,
27 | "strictInjectionParameters": true
28 | }
29 | }
--------------------------------------------------------------------------------
/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "./out-tsc/spec",
5 | "types": [
6 | "jasmine",
7 | "node"
8 | ]
9 | },
10 | "files": [
11 | "src/test.ts",
12 | "src/polyfills.ts"
13 | ],
14 | "include": [
15 | "src/**/*.spec.ts",
16 | "src/**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tslint:recommended",
3 | "rules": {
4 | "align": {
5 | "options": [
6 | "parameters",
7 | "statements"
8 | ]
9 | },
10 | "array-type": false,
11 | "arrow-return-shorthand": true,
12 | "curly": true,
13 | "deprecation": {
14 | "severity": "warning"
15 | },
16 | "component-class-suffix": true,
17 | "contextual-lifecycle": true,
18 | "directive-class-suffix": true,
19 | "directive-selector": [
20 | true,
21 | "attribute",
22 | "app",
23 | "camelCase"
24 | ],
25 | "component-selector": [
26 | true,
27 | "element",
28 | "app",
29 | "kebab-case"
30 | ],
31 | "eofline": true,
32 | "import-blacklist": [
33 | true,
34 | "rxjs/Rx"
35 | ],
36 | "import-spacing": true,
37 | "indent": {
38 | "options": [
39 | "spaces"
40 | ]
41 | },
42 | "max-classes-per-file": false,
43 | "max-line-length": [
44 | true,
45 | 140
46 | ],
47 | "member-ordering": [
48 | true,
49 | {
50 | "order": [
51 | "static-field",
52 | "instance-field",
53 | "static-method",
54 | "instance-method"
55 | ]
56 | }
57 | ],
58 | "no-console": [
59 | true,
60 | "debug",
61 | "info",
62 | "time",
63 | "timeEnd",
64 | "trace"
65 | ],
66 | "no-empty": false,
67 | "no-inferrable-types": [
68 | true,
69 | "ignore-params"
70 | ],
71 | "no-non-null-assertion": true,
72 | "no-redundant-jsdoc": true,
73 | "no-switch-case-fall-through": true,
74 | "no-var-requires": false,
75 | "object-literal-key-quotes": [
76 | true,
77 | "as-needed"
78 | ],
79 | "quotemark": [
80 | true,
81 | "single"
82 | ],
83 | "semicolon": {
84 | "options": [
85 | "always"
86 | ]
87 | },
88 | "space-before-function-paren": {
89 | "options": {
90 | "anonymous": "never",
91 | "asyncArrow": "always",
92 | "constructor": "never",
93 | "method": "never",
94 | "named": "never"
95 | }
96 | },
97 | "typedef-whitespace": {
98 | "options": [
99 | {
100 | "call-signature": "nospace",
101 | "index-signature": "nospace",
102 | "parameter": "nospace",
103 | "property-declaration": "nospace",
104 | "variable-declaration": "nospace"
105 | },
106 | {
107 | "call-signature": "onespace",
108 | "index-signature": "onespace",
109 | "parameter": "onespace",
110 | "property-declaration": "onespace",
111 | "variable-declaration": "onespace"
112 | }
113 | ]
114 | },
115 | "variable-name": {
116 | "options": [
117 | "ban-keywords",
118 | "check-format",
119 | "allow-pascal-case"
120 | ]
121 | },
122 | "whitespace": {
123 | "options": [
124 | "check-branch",
125 | "check-decl",
126 | "check-operator",
127 | "check-separator",
128 | "check-type",
129 | "check-typecast"
130 | ]
131 | },
132 | "no-conflicting-lifecycle": true,
133 | "no-host-metadata-property": true,
134 | "no-input-rename": true,
135 | "no-inputs-metadata-property": true,
136 | "no-output-native": true,
137 | "no-output-on-prefix": true,
138 | "no-output-rename": true,
139 | "no-outputs-metadata-property": true,
140 | "template-banana-in-box": true,
141 | "template-no-negated-async": true,
142 | "use-lifecycle-interface": true,
143 | "use-pipe-transform-interface": true
144 | },
145 | "rulesDirectory": [
146 | "codelyzer"
147 | ]
148 | }
--------------------------------------------------------------------------------