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

ff-validation

v0.1.1

Published

[![Build Status](https://travis-ci.org/frontendfreelancerdk/ff-validation.svg?branch=master)](https://travis-ci.org/frontendfreelancerdk/ff-validation)

Downloads

4

Readme

Build Status

ff-validation

Screenshot

Installing

Npm

npm install ff-validation --save

Include FFModalModule in AppModule imports.

app.module.ts

import {NgModule} from '@angular/core';

import {AppComponent} from './app.component';
import {FFValidationModule} from 'ff-validation';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    FFValidationModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}

Using

Simple usage

properties [ff-validation-errors] and [ff-validation-messages] are required

app.component.html

<ff-validation 
[ff-validation-errors]="myErrorsArr"
[ff-validation-messages]="myMessages">
  <!-- Send your input as content in ff-validation component to be able to add all attributes
  which you need (e.g aria or angular reactive forms attributes)-->
  <!-- !IMPORTANT. Remember you need marked your input with "FFValidationInput" directive -->
  <input type="text" FFValidationInput aria-label="Name">
</ff-validation>

app.component.ts

import {Component} from '@angular/core';

@Component({
  selector: 'ff-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  
  ...
  
  myErrorsArr = [];

  myMessages = {
    'email': 'Field should contain e-mail',
    'required': 'Field is required!',
    'phone': 'Field should contain phone',
    'pattern': 'Field does not match to pattern'
  };
  
  validate(){
    // Implement here your method to validate input or use angular Validator with ReactiveForms
    if(this.inputValue === ''){
      // and just send errors array to ff-validation component
      this.myErrorsArr.push('required')
    }
  }
  
  ...
  
}

Optional

app.component.html

<form [formGroup]="myForm">
  <ff-validation [ff-validation-errors]="myErrors"
                 [ff-validation-messages]="{'required': 'Field is required!',
                                            'pattern': 'Field should contain e-mail'}"
                 [ff-icon-invalid]="myInvalidIcon"
                 [ff-icon-valid]="myValidIcon">
<!-- Also you can put your icon as ng content (e.g. envelope for email input) as on screen below -->
    <i class="icon"></i> 
    <input type="text" placeholder="Email" FFValidationInput [formControlName]="'userEmail'" #email="FFValidationInput">
  </ff-validation>
</form>

<!-- You can change default input icons to your 
Just create a ng-template with your content and define Template Reference Variables (#var)
then put it in ff-validation component [ff-icon-invalid] or [ff-icon-valid] -->
<ng-template #myInvalidIcon>
  <!--  Here can be whatever you want, text, icon,
  some component, button to clear invalid input and so on...-->
  <span>X</span>
</ng-template>

<ng-template #myValidIcon>
  <i class="fa fa-check"></i>
</ng-template>

Screenshot2

Api

###ff-validation component api

[ff-validation-errors] is strings array which contains names of your validation errors.

['required', 'email']

[ff-validation-messages] is object where key is validation error name and value is message.

{required: "Field is required!",
 email: "Field should contain valid e-mail"}

[ff-icon-invalid] and [ff-icon-valid] properties take a template reference variable and replace default icons with yours

###FFValidationInput directive api

Selector: FFValidationInput

Exported as: FFValidationInput

You need marked your input with "FFValidationInput" directive. If you need - you can create local variable and that provides access to directive instance.

<input type="text" FFValidationInput #email="FFValidationInput">

The directive has properties:

  value:string; // input value
  dirty:boolean; // true if input`s default value was changed
  touched:boolean; // true if input was touched
  focused:boolean; // true if input is focused

Styling

You can change default styles.

.ff-validation-input{
/* for input */
}
.ff-validation-errors{
/* for messages wrapper */
}
.ff-invalid{
/* this class will added to .ff-validation-input when input is dirty,
touched and errors array is not empty*/
}
.ff-valid{
/* this class will added to .ff-validation-input when input is dirty,
touched and errors array is empty*/
}

License

MIT © Frontend Freelancer