Generate forms from JSON schemas using AngularJS!
medium.com/@SchemaFormIO / schemaform.io / @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.
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.
Schema Form is a set of AngularJS directives (and a couple of services). It can do two things to make life easier:
- Create a form directly from a JSON schema.
- 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.
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?
- Schema Form integrates deeply with AngularJS and uses AngularJS conventions to handle forms.
- Schema Form uses tv4 for validation, making it compatible with version 4 of the JSON schema standard.
- By default, Schema Form generates Bootstrap 3-friendly HTML.
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.
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>
It's simplest to install Schema Form using Bower.
bower install angular-schema-form
This will install the latest release and basic dependencies. See