1.0.0 • Published 6 years ago
ip-input-lib v1.0.0
ip-input-lib
ip-input-lib is a simple Angular library to provide enhanced user experience for IP input and its validation.
- This library is meant for
<input>elements of HTML form - Library location:
projects/ip-input-libdirectory of this repository
Features
- The directive automatically inserts a
.in the IP address on completion of 3 digits in an IP sub-block. - The directive restricts user from entering an invalid number of digits (i.e. greater than 3) in an IP sub-block.
- On pressing the tab key:
- A
.is inserted and user jumps to the next sub-block of an IP address. - In case the current sub-block is empty, it is automatically populated with a 0 before jumping to the next sub-block or next form field.
- A
- The directive provides IP address validation which is visible from the validity state of the associated
<input>when usingFormsModuleorReactiveFormsModule.
Examples/Demo
- A sample example for IP input in template-driven forms in angular can be found in the
src/appdirectory of this repository.
Installation
npm i ip-input-libUsage
After installing the library, proceed with the following steps to successfully use it.
- Register the
IpInputLibModulein your app module and add it to the imports array of the module.
import { IpInputLibModule } from 'ip-input-lib';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
FormsModule,
IpInputLibModule
],
providers: [],
bootstrap: [AppComponent]
})Note: It is necessary to use at least one from amongst the FormsModule and ReactiveFormsModule to utilize the validation function of the directive.
- The next step differs for template-driven and reactive forms.
Template-driven forms Use the directive selector
ipin your IP<input>field to consume it.Reactive forms i. Add the following import to the typescript file that defines the form:
import {IpInputLibDirective} from 'ip-input-lib'ii. Add the following validator in the synchronous validators array of your input FormControl:IpInputLibDirective.ipAddress
1.0.0
6 years ago