{"id":22214231,"url":"https://github.com/lordazzi/ng-form-helper","last_synced_at":"2026-04-13T18:03:39.426Z","repository":{"id":36476118,"uuid":"227214327","full_name":"lordazzi/ng-form-helper","owner":"lordazzi","description":"Feature set to use in your angular form","archived":false,"fork":false,"pushed_at":"2023-01-07T12:42:40.000Z","size":3254,"stargazers_count":0,"open_issues_count":20,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-28T08:42:02.869Z","etag":null,"topics":["angular","angular7","angular8","ecmascript","form","formulario","javascript","ng7","ng8","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lordazzi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-10T20:57:49.000Z","updated_at":"2021-05-08T18:09:28.000Z","dependencies_parsed_at":"2023-01-17T01:51:30.031Z","dependency_job_id":null,"html_url":"https://github.com/lordazzi/ng-form-helper","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lordazzi%2Fng-form-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lordazzi%2Fng-form-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lordazzi%2Fng-form-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lordazzi%2Fng-form-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lordazzi","download_url":"https://codeload.github.com/lordazzi/ng-form-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245409760,"owners_count":20610603,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular7","angular8","ecmascript","form","formulario","javascript","ng7","ng8","typescript"],"created_at":"2024-12-02T21:14:37.839Z","updated_at":"2026-04-13T18:03:34.406Z","avatar_url":"https://github.com/lordazzi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Form Helper\n## For Angular application (version 7 or over)\n\u003e angulo formularia adjuntor\n\nThis is a simple mask lib with two single directives: a directive to allow field data entry from being just characters mapped by a regular expression and a directive to mask values, it works exclusively for numeric values.\n\n[![npm version](https://badge.fury.io/js/ng-form-helper.svg)](https://badge.fury.io/js/ng-form-helper)\n[![Build Status](https://travis-ci.org/lordazzi/ng-form-helper.svg?branch=master)](https://travis-ci.org/lordazzi/ng-form-helper)\n[![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://github.com/lordazzi/ng-form-helper/blob/documentation/LICENSE)\n\n## Overview\n![Example](./ng-form-helper.gif)\nhttps://lordazzi.github.io/ng-form-helper/\n\n## Installation\n\nFirst execute the following command in the root folder of your angular application:\n\n```npm install ng-form-helper@latest --save```\n\nThen, you must import the library main module in your app.module, like this:\n\n```typescript\nimport { NgModule } from '@angular/core';\nimport { FormsModule } from '@angular/forms';\nimport { BrowserModule } from '@angular/platform-browser';\nimport { FormHelperModule } from 'projects/ng-form-helper/src/public-api';\nimport { AppComponent } from './app.component';\n\n\n@NgModule({\n  declarations: [\n    AppComponent\n  ],\n  imports: [\n    BrowserModule,\n    FormsModule,\n    FormHelperModule\n  ],\n  bootstrap: [\n    AppComponent\n  ]\n})\nexport class AppModule { }\n\n```\n\n## Usage\n\n**The masked field:**\n```html\n  \u003cinput\n    type=\"text\"\n    formFieldMask=\"(99) 9999-9999\"\n    [(ngModel)]=\"masked\"\n  /\u003e\n```\n\n1. Each 9 represents a number.\n2. The mask must finish with a nine.\n3. You should not put any number in the mask but nine, all other charactere are allowed.\n4. The library have not a mask for date but you can create your own using the mask 99/99/9999 and using angular validators to valid the given date.\n\n**The regexed field:**\n```html\n\u003cinput\n  type=\"text\"\n  pattern=\"[0-9]*\"\n  inputmode=\"numeric\"\n  formRegexedField=\"^\\d{0,5}$\"\n  [(ngModel)]=\"regexed\"\n/\u003e\n```\n\n1. It is very cool to block data entry with a regular expression, but it could be not nice for UX: the user could not see that the field just ignore his given value.\n2. Data entry blocked by a RegExp is nice for too large and unmasked number fields, like IMEI, ICCID or other large code.\n3. You should remember that the regular expression will block the field to containing a value that it disagrees with, so do not create a regular expression that represents, for example, a valid email, but write a regular expression that allows input of data of any character allowed in an email.\n\n## Customizing a field\nIn addition to the masks contained in this library, it also contains a class to make it easy to create custom fields in the angular.\nThe abstract directive ```FormFieldDirective``` contain the logic to write data in ReactiveFormsModule, FormsModule and NgModel, you can extends it as the example below (the example is the code of formRegexedField):\n\n```typescript\nimport { Directive, ElementRef, forwardRef, HostListener, Input, Renderer2 } from '@angular/core';\nimport { NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { FormFieldDirective } from './form-field.directive';\n\n@Directive({\n  selector: '[formRegexedField]',\n\n  //  you wil provide only form this field an override\n  //  for angular value acessor, as you can see below\n  providers: [\n    {\n      provide: NG_VALUE_ACCESSOR,\n      useExisting: forwardRef(() =\u003e InputRegexDirective),\n      multi: true\n    }\n  ]\n})\nexport class InputRegexDirective extends FormFieldDirective {\n\n  @Input('formRegexedField')\n  set setRegex(regex: string) {\n    this.regexRule = new RegExp(regex);\n  }\n\n  private regexRule = /(?:)/;\n\n  constructor(\n    //  you must inject this guys as protected\n    protected element: ElementRef,\n    protected renderer: Renderer2\n  ) {\n    super();\n  }\n\n  //  the \"input\" event is the more appropriate to intercept data entry\n  @HostListener('input', ['$event'])\n  onInput(event: KeyboardEvent): void {\n    //  ```getValueFromKeyboardEvent``` is a method from the parent class\n    const value = this.getValueFromKeyboardEvent(event);\n\n    if (this.regexRule.test(value)) {\n      const cursorInitialPosition = this.element.nativeElement.selectionStart;\n\n      //  this set the value in ngModel and in the field.\n      this.updateFieldValue(value);\n      this.setCursorPosition(cursorInitialPosition);\n      return;\n    }\n\n    //  This method will reset either the field value and the cursor position.\n    //  How it works:\n    //  1. The user press the keyboard key\n    //  2. The directive save the state\n    //  3. The key value is delivered to the field\n    //  4. This method will run and, and you choose if you override de value or disagree with it\n    this.resetField();\n  }\n}\n```\n\n## Contributing\n\n### 1. Create an issue\nNo one feature will be implemented without it having an open issue and without which the proposed has been accepted by the team responsible for the project. After the issue is approved, the applicant, a team member or anyone else can open a pull request associated with that issue (just paste the issue link in the pull request).\n\n### 2. Did you find a bug?\nWhen logging a bug, please be sure to include the following:\n * The library version;\n * If at all possible, an *isolated* way to reproduce the behavior;\n * The behavior you expect to see, and the actual behavior.\n\nYou can try to update the library to the last version to see if the bug has already been fixed.\n\n### 3. Do not create a duplicate issue\n[Search the existing issues](https://github.com/lordazzi/ng-form-helper/search?type=Issues) before logging a new one.\n\nSome search tips:\n * *Don't* restrict your search to only open issues. An issue with a title similar to yours may have been closed as a duplicate of one with a less-findable title.\n * Check for synonyms. For example, if your bug involves an interface, it likely also occurs with type aliases or classes.\n\n### 4. Create a Pull Request\nFollow the steps:\n\n * Create a [fork](https://guides.github.com/activities/forking/) from our repository by [clicking here](https://github.com/lordazzi/ng-form-helper/fork), install [node](https://nodejs.org/), do a `git clone` of your forked repository and run `npm install` in the application folder;\n * Create a branch in your forked repository, then code the feature or fix the bug;\n * Run `npm run lint`, `npm run test` and `npm run build` in the repository;\n * Create a Pull Request from your repository to this one, with the issue in the body and some information you think could be usefull to the reviewer (print or a [gif of it working](https://www.screentogif.com/) will be appreciated);\n * The reviewer can ask some changes, don't be mad, this is the GIT Flow process;\n * You get approved and your branch with the feature / fix ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flordazzi%2Fng-form-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flordazzi%2Fng-form-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flordazzi%2Fng-form-helper/lists"}