2.1.0 • Published 1 month ago

@nx-squeezer/ngx-forms v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@nx-squeezer/ngx-forms

CI npm latest version CHANGELOG codecov compodoc renovate semantic-release

This library provides useful extensions for Angular forms, check the documentation to see all available features.

Lazy Validation

Use the following utilities to lazy load large and complex validators. Heavily inspired of this wonderful article from @NetanelBasal.

Provide Lazy Validator in a Directive

@Directive({
  selector: '[lazyValidator]',
  standalone: true,
  providers: [provideLazyValidator(() => import('./validator'))], // Internally provides NG_ASYNC_VALIDATORS
})
export class ValidatorDirective {}
const validator: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {
  // Large and complex validator
};

export default validator; // Note that it works with the default export

In a Form Control

export class FormComponent {
  private readonly formBuilder = inject(FormBuilder);
  readonly formGroup = this.formBuilder.group({
    lazy: this.formBuilder.control('invalid', { asyncValidators: [lazyValidator(() => import('./validator'))] }),
  });
}

Note: the function lazyValidator uses internally inject so it has to be used in an injection context, such as field initalization.

Installation

Do you like this library? Go ahead and use it! It is production ready, with 100% code coverage, protected by integration tests, and uses semantic versioning. To install it:

npm install @nx-squeezer/ngx-forms
2.1.0

1 month ago

2.0.5

2 months ago

2.0.3

3 months ago

2.0.2

3 months ago

2.0.4

3 months ago

2.0.1

3 months ago

2.0.0

5 months ago

1.1.2

8 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.0

10 months ago

0.1.0

10 months ago