AutoFormly

GitHub version Build Status Gitter Coverage Status Codacy Badge

Create Angular-Formly forms with automatic insert and update, and automatic reactive validation. Requires SimpleSchema or Collection2.

Installation

meteor add wieldo:autoformly

How to use it

auto-formly component

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>

Convert all schema fields

const fields = autoFormly.collection(BooksCollection);
// or
const fields = autoFormly.collection($meteor.collection(BooksCollection);
// or
const fields = autoFormly.schema(BooksSchema);

Save object to collection with validation error handling

const fields = autoFormly.collection(BooksCollection);

function submit(book) {
    $meteor.collection(BooksCollection)
        .save(book)
        .then(() => {
            // success
        })
        .catch(() => autoFormly.errors(BooksCollection, fields);
}

Convert all schema fields excluding one

const fields = autoFormly.schema(BooksSchema, {
    fields: {
        published: false
    }
});

Convert selected collection fields

const fields = autoFormly.collection(BooksCollection, {
    all: false,
    fields: {
        published: true,
        author: true,
        title: true
    }
});

Extend formly configuration for selected field

const fields = autoFormly.schema(BooksSchema, {
    all: false,
    fields: {
        published: true,
        author: {
            templateOptions: {
                label: "Written by"
            }
        }
    }
});

What is ready?

See examples above.

Take a look at this docs:

Contributing

It is a new project, at the beginning of development process.

Feel free to ask me anything.

You can help

If you would like to add functionality, just fork this repo and create pull request.

How autoFormly works

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.

What is parser?

Parser is a function that receives simpleSchema key with configuration and reference to formly field configuration object.

So basically, you can add properties to formly configuration by checking field's schema.

Helpers

We're currently working on three other packages that are very useful in autoFormly.

Roadmap 1.0

Contact

You can find me on Gitter.