npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ngserveio/material-forms

v8.1.1

Published

Find more at libraries and examples at [NgServe.io](https://ngserve.io).

Downloads

169

Readme

@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

| Name | Type | Description | | ----------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | fieldName | string | The 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. | | control | AbstractControl | The 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

| Name | Type | Description | | --------- | --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | | label | string | The label of the control and will also act as the fieldName input for the ng-form-field-validation control. | | control | AbstractControl | The 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

| Name | Type | Default Value | Description | | ------------------ | --------------------------------------------- | ------------- | ----------------------------------------------------- | | saveText | string | Save | The save text of the button that submits the form. | | cancelText | string | Cancel | The cancel text of the button that cancels. | | formCssClass | string | { [name: string]: boolean } | empty string | The css class for the form. | | showCancelButton | boolean | true | Determines whether or not to show the cancel button. | | cancelDisabled | boolean | false | Disable the cancel button. | | saveDisabled | boolean | false | Disable the save button. | | saveButtonColor | string | primary | The material color of the display button. | | saveButtonCss | string | { [name: string]: boolean } | empty string | Determines the css for the save button. | | formGroup | FormGroupSubmit | undefined | The form group that helps mark the form as submitted. |

Outputs

| Name | Type | Description | | -------- | -------------------- | ------------------------------------------------ | | cancel | EventEmitter<void> | Emits when the user clicks the cancel button. | | save | EventEmitter<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 Name | Required | Description | | ------------ | -------- | ----------------------------------------------- | | default | yes | This area MUST CONTAIN a material input control | | prefix | no | | | suffix | no | |

ChangeLog.md

File Upload Components

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