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

@codeforges/ng-forms

v0.1.0

Published

Angular 4+ Dynamic form builder, decorate your models to generate forms or create them manually

Downloads

6

Readme

ng-forms (WIP)

This module will make your form building in Angular 4+ easier. Dynamically create reactive forms, as simple as adding a component and provide with required inputs.

Should help reduce repeatable tasks when building forms. The goal is not only make dynamic forms easy to build but even make the process more automated. Imagine a situation when you have new user form
you have a backend endpoint and some interface describing the fields, now the idea is to feed the interface ( better class ) to the ng-forms and it should build the whole new user form for you.

How to use:

Add a this to your AppModule:


@NgModule({
    imports: [
        NgFormsModule
    ],
})
export AppModule

Now you can use the component:

<ng-forms [inputs]="getInputs()" (submit)="doSomeThing($event)"></ng-forms >

Automated usage:

The easiest way to use ng-dynamic-form is to add decorators to your models and extend from DynamicFormModel

// Your model
export class BookModel extends NgDynamicFormsModel {
    private uuid: string;

    @NgFormField({ fieldType: FormFieldType.TEXT })
    private name: string;

    @NgFormField({ fieldType: FormFieldType.TEXT_AREA })
    private description: string;

    @NgFormField({
        fieldType: FormFieldType.SELECT,
        selectOptionKeys: {labelKey: 'name', valueKey: 'id'}
    })
    private authors: {id: string, name: string}[];

    constructor(name: string, description: string, authors: { id: string; name: string }[]) {
        super();
        this.name = name;
        this.description = description;
        this.authors = authors;
    }
}

now in your component you can do the following:

@Component({
    selector: 'my-example-book-form',
    template: '<ng-forms-material [inputs]="getInputs()"></ng-forms-material>'
})
class ExampleComponent {
    private book: BookModel = new BookModel(
        'Test book',
        '',
        [
            {id: '1', name: 'Roger'},
            {id: '2', name: 'Roger2'}
        ]
    );

    public getInputs(): BaseInput[] {
        // For demo purpose BookModel is instantiated here , it can also be a injectable
        return this.book.getFormFields();
    }
}

That is it , the getFormFields() will return an array of FormInputs , it will scan your Model for decorated properties and will use them to build the form.

Manual way

If you need more flexibility you can create the form fields Manual. Lets change the first example a bit.

@Component({
    selector: 'my-example-book-form',
    template: '<ng-forms-material [inputs]="getInputs()"></ng-forms-material>'
})
class ExampleComponent {

    public getInputs(): BaseInput[] {
        // For demo purpose BookModel is instantiated here , it can also be a injectable
        return [
            new TextInput('book-name'),
            new TextAreaInput('book-description'),
        ];
    }
}

Templates

You can override and create custom templates for your forms. Ive made a couple of build in Themes. For example see material design theme.

To use it simply replace the <ng-forms> with <ng-forms-material>

More input coming up, feel free to ask. Npm coming up.