8.0.0 • Published 19 days ago

@ngserveio/material-forms v8.0.0

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

@ngserveio/material-forms

Find more at libraries and examples at NgServe.io.

Read More At: Angular Tutorial - Part 1: Reusable Validation Messages Angular Material Tutorial - Part 2: Creating a Reusable Form Field Component

See the Video Tutorial on YouTube

Angular Reactive Forms Validation with @ngserveio/validation-messages

Running unit tests

Run nx test shared-ui-material-forms to execute the unit tests.

Purpose

This library offers an easier way to validate forms using the Angular Material components.

Import the NgServeMaterialFormsModule

import { NgServeMaterialFormsModule } from '@ngserveio/material-forms';
@NgModule({
  imports: [NgServeMaterialFormsModule],
})
export class SampleModule {}

Form Field Validation Component

Displays the validations messages set on a particular control. Please refer to Validation Error Messages Service for customizing and interpolation of validation messages. This component in conjunction with Validation Display Messages avoids the need for duplicative markup.

Selector

<ng-serve-form-field-validation></ng-serve-form-field-validation>

Inputs

NameTypeDescription
fieldNamestringThe name of the field being validated. Will be used as a default parameter to interpolate in all validation messages. e.g. Message template {{fieldName}} is required.
controlAbstractControlThe control that's being validated.

Example

// Sample Component
import { Validators } from '@angular/forms';
import { FormGroupSubmit } from '@ngserveio/form-services';

@Component({
  template: 'sample-component',
})
export class SampleComponent {
  public formSamples = new FormGroupSubmit({
    firstName: new FormControl('', [Validators.required]),
  });

  public get firstName(): AbstractControl {
    return this.formSamples.get('firstName');
  }
}
<form [formGroup]="formSamples">
  <!-- Please note the firstName name here is a string as a key in the formSamples formGroup -->
  <input type="text" formControlName="firstName" />

  <!-- firstName is the AbstractControl reference in the component code -->
  <ng-serve-form-field-validation [control]="firstName" fieldName="First Name">
  </ng-serve-form-field-validation>
</form>

Form Field

The form field allows you to write less markup for displaying the label and validation and display the projected form field. Please not that the field must be of a MatFormField type.

Inputs

NameTypeDescription
labelstringThe label of the control and will also act as the fieldName input for the ng-form-field-validation control.
controlAbstractControlThe control that's being validated.

Example

// Sample Component
import { Validators } from '@angular/forms';
import { FormGroupSubmit } from '@ngserveio/material-forms';

@Component({
  template: 'sample-component',
})
export class SampleComponent {
  public formSamples = new FormGroupSubmit({
    firstName: new FormControl('', [Validators.required]),
  });

  public get firstName(): AbstractControl {
    return this.formSamples.get('firstName');
  }
}
<!-- Sample Component Markup -->

<form [formGroup]="formSamples">
  <ng-serve-form-field [control]="firstName" label="First Name">
    <input matInput type="text" formControlName="firstName">
  <ng-serve-form-field>
</form>

Form

The form works in conjunction with the FormGroupSubmit. On submit of the form, the formGroup submit will mark FormGroupSubmit as submitted so validations can display based on whether or not the user has tried to submit the form.

Selector

<ng-serve-form></ng-serve-form>

Inputs

NameTypeDefault ValueDescription
saveTextstringSaveThe save text of the button that submits the form.
cancelTextstringCancelThe cancel text of the button that cancels.
formCssClassstring | { [name: string]: boolean }empty stringThe css class for the form.
showCancelButtonbooleantrueDetermines whether or not to show the cancel button.
cancelDisabledbooleanfalseDisable the cancel button.
saveDisabledbooleanfalseDisable the save button.
saveButtonColorstringprimaryThe material color of the display button.
saveButtonCssstring | { [name: string]: boolean }empty stringDetermines the css for the save button.
formGroupFormGroupSubmitundefinedThe form group that helps mark the form as submitted.

Outputs

NameTypeDescription
cancelEventEmitter<void>Emits when the user clicks the cancel button.
saveEventEmitter<void>Emits a save event when the form group is valid.

Example

// Sample Component
import { Validators } from '@angular/forms';
import { FormGroupSubmit } from '@ngserveio/material-forms';

@Component({
  template: 'sample-component',
})
export class SampleComponent {
  public formSamples = new FormGroupSubmit({
    firstName: new FormControl('', [Validators.required]),
  });

  public save(): void {
    console.log(this.formSamples.value);
  }

  public cancel(): void {
    console.log("I've been canceled!  Seems to be the culture.");
  }

  public get firstName(): AbstractControl {
    return this.formSamples.get('firstName');
  }
}
<ng-serve-form [formGroup]="formSamples" (save)="save()" (cancel)="cancel()">
  <ng-serve-form-field [control]="firstName" label="First Name">
    <input matInput type="text" formControlName="firstName">
  <ng-serve-form-field>
</ng-serve-form>

Content Projection

Content NameRequiredDescription
defaultyesThis area MUST CONTAIN a material input control
prefixno
suffixno

ChangeLog.md

File Upload Components

These are components that allow for the display of and help of uploading files.

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.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

5.1.1

1 year ago

5.1.0

1 year ago

5.0.0

1 year ago

4.5.0

2 years ago

4.4.1

2 years ago

4.4.0

2 years ago

4.6.0

2 years ago

4.3.2

2 years ago

4.3.1

2 years ago

4.1.0

2 years ago

4.0.0

2 years ago

4.3.0

2 years ago

4.2.0

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.5

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.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago