8.0.0 • Published 19 days ago

@ngserveio/form-services v8.0.0

Weekly downloads
-
License
-
Repository
-
Last release
19 days ago

@ngserveio/form-services

Find more at libraries and examples at NgServe.io.

Read More At Angular Tutorial - Reusable Form Component with Multiple Controls and Validation

Running unit tests

Run nx test ui-form-services to execute the unit tests.

Purpose

This library extends Angular's FormGroup allowing for a generic form group and validation utilizing @ngserveio/you-good validations.

See the Video Tutorial on YouTube

Shared Validators for Angular and NestJS

FormGroupSubmit

An extension of Angular's FormGroup class that supplies the ability to check if the form has been marked as submitted.

Properties

NameTypeDescription
submitted$BehaviorSubject<boolean>Checks if the form has been marked as submitted

Methods

NameReturn TypeDescription
dispose()voidCompletes the submitted$ property's stream
submit()voidMarks the form as having been submitted and will mark all fields in form as touched.
reset()voidResets the form, marks submitted as false
getFormGroupSubmit(ctrl: AbstractControl)FormGroupSubmit | nullA static method that returns the FormGroupSubmit if the nested parent exists on the ctrl.

ModeledFormGroup

A generic modeled form group that binds the keys of the models to an AbstractControl. Its takes an additional parameter of type (item: T) => PropertyValidationErrors<T>. See @ngserveio/you-good for validation types and examples for validations.

Properties

NameDescription
getChangedValuesSubset<T>Returns the changed values of the controls. Useful for PATCH requests.
type FullName = { firstName: string; lastName: string };

const fullNameValidator = validate<FullName>({
  firstName: propertyValidators(
    (item) => item.firstName,
    [required, emptyOrWhiteSpace]
  ),
  lastName: propertyValidators(
    (item) => item.lastName,
    [required, emptyOrWhiteSpace]
  ),
});

const formGroup = new ModeledFormGroup<FullName>(
  {
    firstName,
    lastName,
  },
  fullNameValidator
);

Subscribing to the modelChanged property provides the defined generic type returned and validates the form in the stream.

formGroup.modelChanged.subscribe(({ firstName, lastName }) => {
  console.log(`${firstName} ${lastName}`);
  // Output: Steve Yzerman
});

formGroup.patchValue({
  firstName: 'Steve',
  lastName: 'Yzerman',
});

Change Log

8.0.0

19 days ago

7.6.2

3 months ago

7.6.1

5 months ago

7.0.0

10 months ago

7.4.0

6 months ago

7.3.0

6 months ago

7.2.1

6 months ago

7.2.0

6 months ago

7.0.2

9 months ago

7.0.1

10 months ago

7.6.0

6 months ago

7.5.0

6 months ago

7.0.0-alpha

10 months ago

6.1.0

1 year ago

6.0.1

1 year ago

6.0.0

1 year ago

5.6.0

2 years ago

5.5.0

2 years ago

5.4.0

2 years ago

5.3.0

2 years ago

5.2.1

2 years ago

5.2.0

2 years ago

5.1.0

2 years ago

5.0.0

2 years ago

4.0.1

2 years ago

3.0.2

2 years ago

2.0.3

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.2

2 years ago

1.0.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

0.0.1

2 years ago