Create Angular-Formly forms with automatic insert and update, and automatic reactive validation. Requires SimpleSchema or Collection2.
meteor add wieldo:autoformly
Add autoFormly and angular-formly templates to your angular module.
angular.module('app', [
'autoFormly',
'formlyMaterial' // or other angular-formly templates
]);As you can see above, I'm using angular-formly-templates-material which I also maintain. You can add it using meteor add formly:angular-formly-templates-material.
Be aware that not all angular-formly templates have same API
It is not yet a stable version
If you found some mismatch with other templates, post an issue
To insert or update collection
<auto-formly
collection="vm.booksCollection"
doc="vm.book"
options="vm.options"
on-success="vm.onSuccess"
on-error="vm.onError">
<button type="submit">Update</button>
</auto-formly>- collection Mongo.Collection object
- doc document from collection (optional)
- options same object as in autoFormly.collection (to custom configuration and filtering) (optional)
- onSuccess callback with result of action as argument (optional)
- onError callback with error as argument (false if form contains errors on client-side) (optional)
const fields = autoFormly.collection(BooksCollection);
// or
const fields = autoFormly.collection($meteor.collection(BooksCollection);
// or
const fields = autoFormly.schema(BooksSchema);const fields = autoFormly.collection(BooksCollection);
function submit(book) {
$meteor.collection(BooksCollection)
.save(book)
.then(() => {
// success
})
.catch(() => autoFormly.errors(BooksCollection, fields);
}const fields = autoFormly.schema(BooksSchema, {
fields: {
published: false
}
});const fields = autoFormly.collection(BooksCollection, {
all: false,
fields: {
published: true,
author: true,
title: true
}
});const fields = autoFormly.schema(BooksSchema, {
all: false,
fields: {
published: true,
author: {
templateOptions: {
label: "Written by"
}
}
}
});We're currently working on three other packages that are very useful in autoFormly.
- formlyTransformer to simplify process of formly field transformation.
- formlyValidator to make validation easier (with built-in validators)
- formlyMaterial is a AngularJS module with Angular Material templates to use in angular-formly.
See examples above.
- creating formly fields with validators using collection or schema (autoFormly.collection(), autoFormly.schema())
- handling validation errors (autoFormly.errors() sets validation on form fields)
Take a look at this docs:
It is a new project, at the beginning of development process.
Feel free to ask me anything.
If you would like to add functionality, just fork this repo and create pull request.
Basically it parses simpleSchema structure and creates formly configuration for each field.
For example, to mark field as required we can create the parser function to check if optional property is being used. If opional is not set to true then we're adding required validator from wieldo:angular-formly-validator package (see formlyValidator and source code in required.js.
Parser is a function that receives simpleSchema key with configuration and reference of formly field configuration object.
So basically, you can add properties to formly configuration by checking field's schema.
- Component to automate process of insertion or collection update
-
schema.minCountandschema.maxCountsupport - Support for Object type fields
- Support for array of objects
- Interactive demo
- Extend SimpleSchema to use
autoformlyproperty - Add optional manual formly configuration for each field
- More advanced field filtering (show all / hide all / add excluding)
-
schema.keyasformly.key -
schema.labelasformly.templateOptions.label -
schema.optionaland required validator -
schema.maxfor String and Number types as maxlength and maxnumber validator -
schema.minfor String and Number types as minlength and minnumber validator -
schema.regExas pattern validator -
schema.defaultValueasformly.defaultValue -
schema.autoformly.templateOptions.rowsto be displayed as textarea - Boolean type as checkbox
-
schema.autoformly.typeto beformly.type -
schema.allowedValuesas select element (schema type is a String) - validation for
schema.allowedValues - Support for Date type fields with min and max
- Support for server-side validation errors (like unique)
You can find me on Gitter.