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

@zupit-it/ng-form

v0.1.0

Published

An Angular library to ease the management of Angular Forms.

Downloads

1

Readme

ng-form

An Angular library to ease the management of Angular Forms.

What does it provide?

  • Form wrapper to handle enabling/disabling of the form, form submit only when form is valid, etc.
  • Useful form validators.
  • Useful form utilities.
  • Form directive to attach to form tag to handle form submit only when data is valid.

Is it ready to use?

The library is in an early development stage, but is well-tested and all implemented features work.

Please keep in mind that it might still change a lot.

Feel free to try it out and suggest a feature or contribute yourself if you feel that something is wrong or missing.

Installation

npm install -D @zupit-it/ng-form

Docs

Components

FormComponent

The FormComponent is a wrapper that substitute the tag in your templates for a better form management. It allows you to enable or disable the form from its inputs, to keep some fields disabled such as read only fields and to submit the form only when the data is valid.

Inputs
  • form!: FormGroup The FormGroup control that contains all form data.

  • formDataLoaded?: boolean A flag to know whether all async data necessary to the form were correctly downloaded or not. The form remain disabled until all necessary data is downloaded.

  • enabled = false A flag to specify whether the form should be enabled or not. It depends also on formDataLoaded flag, if it is false the form will be disabled even if enabled is true.

  • disabledFields: string[] = [] Allows to keep some fields disabled when the form is enabled. This allows to handle read only fields.

  • forceEnabling = false Force the enabling of the form even if the form is enabled. Might be useful if the form is always enabled but at some point you need to disable some fields.

  • footerStyleClass = '' CSS classes to apply to the footer of the component.

  • contentStyleClass = '' CSS classes to apply to the content section of the component.

  • formStyleClass = '' CSS classes to apply to the form section of the component.

  • showFooter = true Whether to show or not the footer.

  • modelToFormValueMapper: (instance: Model) => unknown A function which maps the instance model to the form value. This is useful when the form value is different from the instance model.

  • formValueToModelMapper: (formValue: unknown) => Model A function which maps the form value to the instance model. This is useful when the form value is different from the instance model.

  • instance: Model | undefined The instance model of the form. It is used to initialize the form value and to map the form value to the instance model.

Outputs
  • formSubmit = new EventEmitter<Model>() Emit the data when the form is submitted and valid. The emitted data follows the structure of the instance model, which might differ from the form data.
Methods
  • submittable(): boolean Returns whether the form is valid or not.

  • pristine(): boolean Returns whether the form is pristine or not.

Directives

FormSubmitDirective

The FormSubmitDirective is a directive which handles the form submit of a form. It is useful when you want to handle the form submit only when the form is valid.

Inputs
  • form!: FormGroup The FormGroup control that contains all form data. Required to know whether the data is valid or not.
Outputs
  • ngFormSubmit = new EventEmitter<Event>() Emit the data when the form is submitted and valid. If data is not valid, a FormException error is thrown.

Validators

Set of useful validators to validate common fields, like password, email, phone number, etc.

passwordValidators

Field validators to check that the password is required and that the password is strong enough.

matchPassword

Form validator to check that two password fields match.

notBlank

Field validator to check that the field is not null and not empty.

email

Field validator to check that the field is a valid email.

phoneNumber

Field validator to check that the field is a valid phone number.

maxDate

Field validator to check that the field is before a max date.

minDate

Field validator to check that the field is after a min date.

startDateBeforeOrEqualEndDate

Form validator to check that the start date is before or equal to the end date.

Form Utilities

Set of utilities to handle forms.

setFormEnabled

Utility to enable or disable a form. It allows to keep some fields disabled when the form is enabled. This utility does nothing if the form is already in the desired state, except if the flag force is true.

updateFormTreeValueAndValidity

Allows to update the value and validity of a form and all its children. The standard method updateValueAndValidity available in the AbstractControl class updates only its own value and validity.

hasAnyRequiredErrors

Utility to check whether a form has any required errors or not.

validateForm

Utility that checks whether the form is valid, there are missing required fields or is invalid. It marks the form as touched.

validateFormWithException

Utility that throws a FormException if the form is invalid or there are missing required fields. It marks the form as touched.

Development & Contribution

Setup the project:

   npm install
   npm run prepare

If you want to contribute, please contact open an issue so we can discuss about it. Then simply do your modifications, add tests to them, and simply submit a change request.

IDEAS & TODOs:

  • Add registration mechanism for common roles checking to improve re-usability
  • Centralize events in a service that can be subscribed (on login, on logout, on auth expired, ...)