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

angular18-json-form

v0.0.3

Published

Angular JSON Form Library =========================

Downloads

5

Readme

Angular JSON Form Library

The Angular JSON Form Library (angular18-json-form) provides a dynamic and flexible way to create forms based on JSON configuration. It supports various input types, validations, custom styling, and error handling.

Features

  • Dynamic Form Generation: Create forms based on JSON configuration.

  • Various Input Types: Supports text, number, email, select, checkbox, radio, and file inputs.

  • Custom Styling: Apply custom classes and styles to individual fields and the entire form.

  • Validation Support: Includes built-in and custom validations.

  • Error Handling: Dynamically handle and display validation errors.

  • Customizable Labels: Set custom labels with styling options.

Installation

To install the library, use npm:

npm install angular18-json-form

Usage

Import the Library

Import the JsonFormModule into your Angular module:

import { AngularJsonForm } from 'angular18-json-form'

@NgModule({
  imports: [
    // other imports
    AngularJsonForm
  ],
  // other module settings
})
export class AppModule { }

Basic Usage

Use the component in your template and pass the configuration via the config input property.

Example Configuration

const formConfig = {
  globalLabelClass: 'global-label-class',
  globalLabelStyle: {
    'font-weight': 'bold',
    'color': '#333'
  },
  formConfig: {
    class: 'custom-form-class',
    style: {
      'padding': '20px',
      'background-color': '#f9f9f9'
    },
    buttonClass: 'custom-button-class',
    buttonStyle: {
      'background-color': '#007bff',
      'color': '#fff',
      'border': 'none',
      'padding': '10px 20px',
      'border-radius': '5px'
    }
  },
  fields: [
    {
      name: 'username',
      type: 'text',
      label: 'Username',
      class: 'custom-input-class',
      style: {
        'border': '1px solid #ccc'
      },
      labelClass: 'custom-label-class',
      labelStyle: {
        'color': 'blue'
      },
      errorClass: 'custom-error-class',
      errorStyle: {
        'color': 'red',
        'font-size': '12px'
      },
      validations: [
        { name: 'required' },
        { name: 'minlength', value: 3 },
        { name: 'pattern', value: '^[a-zA-Z0-9]*$' }
      ]
    },
    {
      name: 'email',
      type: 'email',
      label: 'Email',
      validations: [
        { name: 'required' },
        { name: 'email' }
      ]
    },
    // Add more fields as needed
  ]
};

Using the Component

In your component template:

<angular-json-form [json]="formConfig" (onSubmit)="onSubmit($event)"></angular-json-form>

In your component class:

export class AppComponent {
  formConfig = formConfig;
}

Configuration Options

formConfig

  • class: Custom class for the form element.

  • style: Custom style for the form element.

  • buttonClass: Custom class for the submit button.

  • buttonStyle: Custom style for the submit button.

fields

Each field in the fields array can have:

  • name: Field name.

  • type: Input type (text, number, email, select, checkbox, radio, file).

  • label: Field label.

  • class: Custom class for the input element.

  • style: Custom style for the input element.

  • labelClass: Custom class for the label element.

  • labelStyle: Custom style for the label element.

  • errorClass: Custom class for error messages.

  • errorStyle: Custom style for error messages.

  • validations: Array of validation rules:

    • name: Validation type (required, minlength, maxlength, pattern, email, max, min).

    • value: Validation value (e.g., minimum length).

Example

Here’s a full example of a form configuration and how to use it in your Angular application.

JSON Configuration

const formConfig = {
  globalLabelClass: 'global-label-class',
  globalLabelStyle: {
    'font-weight': 'bold',
    'color': '#333'
  },
  formConfig: {
    class: 'custom-form-class',
    style: {
      'padding': '20px',
      'background-color': '#f9f9f9'
    },
    buttonClass: 'custom-button-class',
    buttonStyle: {
      'background-color': '#007bff',
      'color': '#fff',
      'border': 'none',
      'padding': '10px 20px',
      'border-radius': '5px'
    }
  },
  fields: [
    {
      name: 'username',
      type: 'text',
      label: 'Username',
      class: 'custom-input-class',
      style: {
        'border': '1px solid #ccc'
      },
      labelClass: 'custom-label-class',
      labelStyle: {
        'color': 'blue'
      },
      errorClass: 'custom-error-class',
      errorStyle: {
        'color': 'red',
        'font-size': '12px'
      },
      validations: [
        { name: 'required' },
        { name: 'minlength', value: 3 },
        { name: 'pattern', value: '^[a-zA-Z0-9]*$' }
      ]
    },
    {
      name: 'email',
      type: 'email',
      label: 'Email',
      validations: [
        { name: 'required' },
        { name: 'email' }
      ]
    },
    {
      name: 'subscribe',
      type: 'checkbox',
      label: 'Subscribe to Newsletter',
      class: 'custom-checkbox-class',
      style: {
        'margin': '10px 0'
      }
    },
    {
      name: 'gender',
      type: 'radio',
      label: 'Gender',
      options: [
        { value: 'male', label: 'Male' },
        { value: 'female', label: 'Female' }
      ]
    },
    {
      name: 'profilePicture',
      type: 'file',
      label: 'Profile Picture'
    }
  ]
};

Component Usage

In your component template:

<angular-json-form [json]="formConfig" (onSubmit)="onSubmit($event)"></angular-json-form>

In your component class:

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

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

Contributing

Feel free to contribute by submitting issues, feature requests, or pull requests. Please follow the contribution guidelines.

License

This library is licensed under the MIT License.

Contact

For questions or feedback, please contact [email protected].