1.0.0 • Published 3 years ago

carey-validation v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

Carey Development Logo

Carey Development Angular Validation

license

Overview

This package streamlines validation displays for Angular Material forms.

The point is to reduce the amount of code developers need to add to display validation errors on forms.

The library handles two types of error displays: 1. Individual errors - errors that typically appear next to or below the erroneous field. 2. Summary errors - lists that summarize all errors on a form, usually displayed at the top or bottom of the form.

As of now, the library only supports Angular Material forms.

Usage: Individual Error Messages

The easiest way to add error display to a form is with the <mat-error> element. For example: <mat-error fieldLabel="First name" [simpleValidation]="basicInfoFormGroup.get('firstName')"></mat-error>

The fieldLabel property is optional but helpful. If used, the error will appear with the field name. For example: "First name is required."

If you omit the fieldLabel property, users will see a generic error message: "This field is required."

The simpleValidation takes a form field as its input. It will validate that field according to the rules you specify in the component class. Yes, you must still specify the validation rules.

Usage: Summary Error Messages

If you want to display a summary of error messages use the <error-spree> element. For example: <error-spree [errorMessages]="errorMessages"></error-spree>

In the code above, errorMessages is an array of strings representing all errors on the entire form.

You can get all errors with the help of the ValidationService class provided in this library. For example: let basicInfoForm: FormGroup = basicInfoComponent.basicInfoFormGroup; let errorMessages: string[] = this.validationService.validateForm(basicInfoForm);

That will grab all the errors from that form.

A caveat, though: you need to configure error messages for fields not covered by the library.

As it stands now, the library will provide default messages for fields with the following names:

  • firstName
  • lastName
  • email

If you want to provide messages for other fields, you can add them as an array in the fieldSummaries property of the configuration object.

An example: export const allFieldSummaries: ErrorFieldMessage[] = [ { field: "source", message: "Please enter a valid source" }, { field: "status", message: "Please enter a valid status" }, { field: "account", message: "Please enter a valid account" } ];

Then just specify that array when importing the module as follows: ValidationModule.forRoot({ fieldSummaries : allFieldSummaries })

1.0.0

3 years ago

0.4.3

3 years ago

0.3.9-a

3 years ago

0.4.1-c

3 years ago

0.4.1-b

3 years ago

0.4.1-a

3 years ago

0.3.8

3 years ago

0.3.9

3 years ago

0.3.8-a

3 years ago

0.3.8-b

3 years ago

0.4.0-d

3 years ago

0.4.0-c

3 years ago

0.4.0-b

3 years ago

0.4.0-a

3 years ago

0.4.0-f

3 years ago

0.4.0-e

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.2

3 years ago

0.3.6-a

3 years ago

0.3.6-c

3 years ago

0.3.7-a

3 years ago

0.3.6-b

3 years ago

0.3.6-e

3 years ago

0.3.6-d

3 years ago

0.3.6-f

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.7

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.0

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago