Convert Figma logo to code with AI

json-schema-form logoangular-schema-form

Generate forms from a JSON schema, with AngularJS!

2,467
653
2,467
129

Top Related Projects

95,657

Deliver web apps with confidence 🚀

JavaScript powered forms for AngularJS

📝 JSON powered / Dynamic forms for Angular

Angular Smart Data Table component

A React component for building Web forms from JSON Schema.

Quick Overview

Angular Schema Form is a popular library for generating dynamic forms in Angular applications based on JSON schemas. It simplifies the process of creating complex forms by allowing developers to define form structures using JSON, which are then automatically rendered as Angular forms with built-in validation and customization options.

Pros

  • Reduces development time by automating form generation from JSON schemas
  • Provides a wide range of built-in form controls and widgets
  • Supports custom form layouts and field types
  • Integrates well with Angular's form validation system

Cons

  • Learning curve for complex form configurations
  • Limited flexibility for highly customized form designs
  • Documentation can be outdated or incomplete in some areas
  • May require additional plugins for advanced features

Code Examples

  1. Basic form generation:
import { Component } from '@angular/core';
import { SchemaFormModule } from 'angular-schema-form';

@Component({
  selector: 'app-form',
  template: '<sf-form [schema]="schema" [model]="model" (onSubmit)="onSubmit($event)"></sf-form>'
})
export class FormComponent {
  schema = {
    type: 'object',
    properties: {
      name: { type: 'string', title: 'Name' },
      email: { type: 'string', title: 'Email', format: 'email' }
    }
  };
  model = {};

  onSubmit(form) {
    console.log(form);
  }
}
  1. Custom field type:
import { Component } from '@angular/core';
import { FieldType } from 'angular-schema-form';

@Component({
  selector: 'custom-field',
  template: '<input [formControl]="control" [attr.placeholder]="schema.placeholder">'
})
export class CustomFieldComponent extends FieldType {}

// Register custom field
SchemaFormModule.FIELD_TYPE_COMPONENTS['custom'] = CustomFieldComponent;
  1. Conditional fields:
schema = {
  type: 'object',
  properties: {
    type: { type: 'string', enum: ['personal', 'business'] },
    companyName: { type: 'string', title: 'Company Name' }
  },
  required: ['type']
};

form = [
  'type',
  {
    key: 'companyName',
    condition: 'model.type === "business"'
  }
];

Getting Started

  1. Install the library:

    npm install angular-schema-form
    
  2. Import the module in your Angular app:

    import { SchemaFormModule } from 'angular-schema-form';
    
    @NgModule({
      imports: [SchemaFormModule.forRoot()],
      // ...
    })
    export class AppModule { }
    
  3. Use the sf-form component in your template:

    <sf-form [schema]="schema" [model]="model" (onSubmit)="onSubmit($event)"></sf-form>
    
  4. Define your schema and model in the component:

    schema = {
      type: 'object',
      properties: {
        name: { type: 'string', title: 'Name' },
        email: { type: 'string', title: 'Email', format: 'email' }
      }
    };
    model = {};
    

Competitor Comparisons

95,657

Deliver web apps with confidence 🚀

Pros of Angular

  • Full-featured framework for building complex web applications
  • Large ecosystem with extensive documentation and community support
  • Powerful CLI for scaffolding, development, and build processes

Cons of Angular

  • Steeper learning curve compared to Angular Schema Form
  • More complex setup and configuration for simple form-based applications
  • Larger bundle size, which may impact initial load times

Code Comparison

Angular Schema Form:

$scope.schema = {
  type: "object",
  properties: {
    name: { type: "string", title: "Name" },
    email: { type: "string", title: "Email", format: "email" }
  }
};
$scope.form = ["*"];

Angular:

@Component({
  selector: 'app-form',
  template: `
    <form [formGroup]="form">
      <input formControlName="name" placeholder="Name">
      <input formControlName="email" type="email" placeholder="Email">
    </form>
  `
})
export class FormComponent {
  form = new FormGroup({
    name: new FormControl(''),
    email: new FormControl('')
  });
}

Angular Schema Form is specifically designed for creating forms based on JSON schemas, making it easier to generate forms from data models. It's more lightweight and focused on form generation.

Angular, on the other hand, is a comprehensive framework that provides a complete solution for building web applications. It offers more flexibility and control over the entire application structure but requires more setup for simple form-based scenarios.

JavaScript powered forms for AngularJS

Pros of angular-formly

  • More flexible and customizable, allowing for complex form structures
  • Better integration with Angular's ecosystem and best practices
  • Extensive documentation and community support

Cons of angular-formly

  • Steeper learning curve due to its flexibility
  • Requires more code to set up basic forms compared to angular-schema-form
  • May be overkill for simple form scenarios

Code Comparison

angular-schema-form:

$scope.schema = {
  type: "object",
  properties: {
    name: { type: "string", title: "Name" },
    email: { type: "string", title: "Email", format: "email" }
  }
};

angular-formly:

$scope.fields = [
  {
    key: 'name',
    type: 'input',
    templateOptions: {
      label: 'Name'
    }
  },
  {
    key: 'email',
    type: 'input',
    templateOptions: {
      label: 'Email',
      type: 'email'
    }
  }
];

Both libraries offer solutions for generating forms in Angular applications, but angular-formly provides more flexibility and integration with Angular's ecosystem at the cost of a steeper learning curve. angular-schema-form is more straightforward for simple forms but may be limited for complex scenarios.

📝 JSON powered / Dynamic forms for Angular

Pros of ngx-formly

  • More flexible and customizable, allowing for complex form structures
  • Better TypeScript support and type inference
  • Actively maintained with frequent updates and a larger community

Cons of ngx-formly

  • Steeper learning curve due to its flexibility and advanced features
  • Less straightforward for simple forms compared to angular-schema-form
  • Requires more manual configuration for basic use cases

Code Comparison

angular-schema-form:

$scope.schema = {
  type: "object",
  properties: {
    name: { type: "string", title: "Name" },
    email: { type: "string", title: "Email", format: "email" }
  }
};

ngx-formly:

export class AppComponent {
  form = new FormGroup({});
  model = {};
  fields: FormlyFieldConfig[] = [
    { key: 'name', type: 'input', templateOptions: { label: 'Name' } },
    { key: 'email', type: 'input', templateOptions: { label: 'Email', type: 'email' } }
  ];
}

Both libraries aim to simplify form creation in Angular applications, but they take different approaches. angular-schema-form focuses on generating forms from JSON schemas, making it easier for simple use cases. ngx-formly, on the other hand, provides a more programmatic approach with greater flexibility and customization options. The choice between the two depends on the complexity of your forms and your preference for configuration style.

Angular Smart Data Table component

Pros of ng2-smart-table

  • Built specifically for Angular 2+, offering better integration and performance
  • Provides a rich set of features out-of-the-box, including sorting, filtering, and pagination
  • Offers a more flexible and customizable table structure

Cons of ng2-smart-table

  • Limited to table-based data presentation, whereas angular-schema-form is more versatile for various form types
  • May require more setup and configuration for complex use cases
  • Less focus on form validation compared to angular-schema-form

Code Comparison

angular-schema-form:

<form sf-schema="schema" sf-form="form" sf-model="model"></form>

ng2-smart-table:

<ng2-smart-table [settings]="settings" [source]="data"></ng2-smart-table>

Both libraries aim to simplify data presentation and manipulation in Angular applications, but they serve different purposes. angular-schema-form is more focused on generating forms based on JSON schemas, while ng2-smart-table specializes in creating feature-rich, interactive tables.

angular-schema-form offers a more declarative approach to form generation, making it easier to create complex forms with less code. On the other hand, ng2-smart-table provides a powerful solution for displaying and manipulating tabular data with built-in features like sorting and filtering.

The choice between these libraries depends on the specific requirements of your project. If you need a versatile form generator, angular-schema-form might be more suitable. For advanced table functionality, ng2-smart-table could be the better option.

A React component for building Web forms from JSON Schema.

Pros of react-jsonschema-form

  • Built for React, offering seamless integration with React applications
  • More active development and larger community support
  • Extensive documentation and examples available

Cons of react-jsonschema-form

  • Steeper learning curve for developers not familiar with React
  • Less flexibility in customizing form layout compared to angular-schema-form
  • May require additional setup for complex form scenarios

Code Comparison

angular-schema-form:

$scope.schema = {
  type: "object",
  properties: {
    name: { type: "string", title: "Name" },
    age: { type: "number", title: "Age" }
  }
};
$scope.form = ["*"];

react-jsonschema-form:

const schema = {
  type: "object",
  properties: {
    name: { type: "string", title: "Name" },
    age: { type: "number", title: "Age" }
  }
};
const uiSchema = {};

return <Form schema={schema} uiSchema={uiSchema} />;

Both libraries use JSON Schema to define form structure, but react-jsonschema-form requires a separate uiSchema for advanced customization. angular-schema-form allows more concise form definitions with its form array syntax.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Angular Schema Form

npm version npm downloads Gitter Build Status Code Coverage

Generate forms from JSON schemas using AngularJS!

Why not many changes lately?

Much of the new development is being done in Assimilate, a standardised validator for JSON Schema to help ensure changing validators is never as painful as escaping tv4 is, as well as a new core library to allow for a more predictable upgrade from AngularJS to Angular.

The Blog / The Web Site / The Twitter / The Movie

medium.com/@SchemaFormIO / website / @SchemaFormIO / Movie

If you use ASF in your project/company please let us know! We'd love to feature you on the site.

There has been some recent developments in this project that you might want to read about.

Demo Time!

Try out the example page. Try editing the schema or form definition and see what comes out!

Hint: By pressing the 'Save to gist' button (top left), you can save your example into a shareable link.

Documentation

You can find all documentation here, it covers all the different field types and their options.

It also covers how to extend angular schema form with your own field types.

Before filing an issue, please read our issue support instructions or you may be ignored.

What is it?

Schema Form is a set of AngularJS directives (and a couple of services). It can do two things to make life easier:

  1. Create a form directly from a JSON schema.
  2. Validate form fields against that same JSON schema.

Schema Form uses convention over configuration, so it comes packaged with some sensible defaults. But you can always customize it by changing the order and types of form fields.

JSON Form

Schema Form is inspired by the nice JSON Form library and aims to be roughly compatible with it, especially its form definition. So what sets Schema Form apart from JSON Form?

  1. Schema Form integrates deeply with AngularJS and uses AngularJS conventions to handle forms.
  2. Schema Form uses tv4 for validation, making it compatible with version 4 of the JSON schema standard.
  3. By default, Schema Form generates Bootstrap 3-friendly HTML.

Migration Guide

If you already use the library factories in an app or an add-on or plan to upgrade versions, please read the migration guide for any items that may need consideration.

Basic Usage

First, expose your schema, form, and model to the $scope.

angular.module('myModule', ['schemaForm'])
       .controller('FormController', function($scope) {
  $scope.schema = {
    type: "object",
    properties: {
      name: { type: "string", minLength: 2, title: "Name", description: "Name or alias" },
      title: {
        type: "string",
        enum: ['dr','jr','sir','mrs','mr','NaN','dj']
      }
    }
  };

  $scope.form = [
    "*",
    {
      type: "submit",
      title: "Save"
    }
  ];

  $scope.model = {};
});

Then load them into Schema Form using the sfSchema, sfForm, and sfModel directives.

<div ng-controller="FormController">
    <form sf-schema="schema" sf-form="form" sf-model="model"></form>
</div>

Installation

NPM

npm i angular-schema-form@latest

For the latest pre-release (alpha)

npm i angular-schema-form@pre-release

Bower

It's simplest to install Schema Form using Bower. If you use the bootstrap decorator use the one from the angular-schema-form-bootstrap repo

bower install angular-schema-form angular-schema-form-bootstrap
bower install angular-schema-form angular-schema-form-bootstrap

This will install the latest release and basic dependencies. See dependencies section below.

You can also load the files via cdnjs.com.

Manual

You can also just download the contents of the dist/ folder and add dependencies manually.

Dependencies

Schema form has a lot of dependencies, most of which are optional. Schema Form depends on:

  1. AngularJS version 1.3.x is recommended. Version 1.2.x has some limitation. See known limitations.
  2. angular-sanitize
  3. tv4
  4. bootstrap 3

If you install via bower you get all of the above except bootstrap since we don't want to push a certain version or flavor on you. Also make sure you got the angular version you actually want.

Additional dependencies

  1. If you'd like to use drag-and-drop reordering of arrays, you'll also need ui-sortable and its jQueryUI dependencies. See the ui-sortable documentation for details about which parts of jQueryUI are needed. You can safely ignore these if you don't need reordering.
  2. Schema Form provides tabbed arrays through the form type tabarray. Tab arrays default to tabs on the left side. For these to work, you'll need to include the CSS from bootstrap-vertical-tabs. However, you won't need Bootstrap Vertical Tabs for horizontal tabs (the tabType: "top" option).

The minified files include templates - no need to load additional HTML files.

Script Loading

Schema form is split into two main files, dist/schema-form.min.js and dist/bootstrap-decorator.min.js and they need be loaded in that order. AngularJS, tv4 and objectpath also needs to be loaded before Schema Form.

<script type="text/javascript" src="bower_components/angular/angular.min.js"></script>
<script type="text/javascript" src="bower_components/angular-sanitize/angular-sanitize.min.js"></script>
<script type="text/javascript" src="bower_components/tv4/tv4.js"></script>
<script type="text/javascript" src="bower_components/objectpath/lib/ObjectPath.js"></script>
<script type="text/javascript" src="bower_components/angular-schema-form/dist/schema-form.min.js"></script>
<script type="text/javascript" src="bower_components/angular-schema-form/dist/bootstrap-decorator.min.js"></script>

Module loading

Don't forget to load the schemaForm module or nothing will happen.

angular.module('myModule', ['schemaForm']);

Add-ons

There are several add-ons available, for a full list see the web page. Your can also create your own add-ons!

Contributing

Contributions are welcome! Please see Contributing.md for more info.

Building

The new Webpack compilation has made it easier to manage files and code and run build scripts, but it is still not easy enough for users unfamiliar with it... yet.

NOTE in order to build simultaneously with json-schema-form-core you must have it cloned as a sibling directory to this one OR npm install the version you wish to build with.

Webpack now generates a header to indicate version and date of build. Do not create PR with the DIST folder.

Branch Status & New Add-On

This branch will be the next version of Angular Schema Form, currently please use the examples/example.html file as the best example to get the framework working.

The example uses angular-schema-form.js and angular-schema-form-bootstrap.js for the version of the code it executes, if you want your page to behave the same you obviously need the same version!

Add-on

To see how to make an add-on work I have now included the calculate add-on file within the examples/add-on directory.

Tests

Unit tests are run with karma and written using mocha, chai and sinon

To run the tests:

  1. Install all dependencies via NPM.
  2. Install dev dependencies with bower.
  3. Install the Karma CLI.
  4. Run the tests using npm test.
$ npm install
$ bower install
$ npm test

NPM DownloadsLast 30 Days