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

vue-forminator

v1.0.0-beta.4

Published

Vue.js schema based form generator

Downloads

6

Readme

vue-forminator

CircleCI

Forminator is a "no magic", extensible, configurable, schema-based form fields factory.

import Vue from 'vue';
import Forminator from 'vue-forminator';

new Vue({
    render(h) {
        return (<form>
            <Forminator schema={schema} model={form} />
        </form>)
    },
    data() {
        return {
            form: {}
        }
    },
    computed: {
        schema => ([
            [
                { name: 'firstName', label: 'First name' },
                { name: 'lastName', label: 'Last name' }
            ],
            { name: 'email', label: 'Email address', as: 'email' },
            { name: 'acceptedTerms', label: 'Accept terms', as: 'boolean' },
        ])
    },
}).$mount('#app')

Why you (may) need it?

  • your project involves many forms
  • your form markup is complicated
  • you are seeing a lot of duplicated code in your form components
  • your forms look inconsistent
  • maintainance takes to much time

Integrations

// Bootstrap (v4.1)
import BootstrapForminator from 'vue-forminator/lib/presets/bootstrap';

// Bulma
import BulmaForminator from 'vue-forminator/lib/presets/bulma';

Schema definition

text|number|email

{
    as: 'text|number|email',
    name: 'fieldName',
    attrs: {
        // html attributes passed to input element, for example:
        placeholder: 'Field label',
        class: 'customInputClass',
        ...
    }
}

checkbox|boolean

{
    as: 'boolean',
    name: 'fieldName',
    attrs: {
        // html attributes passed to input element, for example:
        class: 'customInputClass',
        ...
    }
}

select

{
    as: 'select',
    name: 'fieldName',
    attrs: {
        // html attributes passed to input element, for example:
        class: 'customInputClass',
        ...
    },
    options: [
        {
            value: 'optionValue',
            label: 'Option text label',
            attrs: {
                // html attributes passed to option element, for example:
                disabled: 'disabled',
                ...
            }
        },
        ...
    ]
}

radio

{
    as: 'radioGroup',
    name: 'fieldName',
    options: [
        {
            value: 'optionValue',
            label: 'Option text label',
            attrs: {
                // html attributes passed to input element, for example:
                disabled: 'disabled',
                ...
            }
        },
        ...
    ]
}

Rows and columns

row field type can be used to render fields inline. It generates div element with config.rowClass css class followed by set of divs (columns) with config.columnClass css class.

// short version, filled with default values
[
    { name: 'firstName', as: 'text' },
    { name: 'email', as: 'email' },
],

// long version for inplace costumization
{
    as: 'row',
    attrs: {
        // html attributes passed to row wrapper element, for example:
        class: 'row space-around',
        ...
    },
    columns: [
        { as: 'text', name: 'address' }, // shorthand for default column definition

        // long version for inplace customization
        {
            as: 'column',
            attrs: {
                // html attributes passed to column wrapper element, for example:
                class: 'col col-sm-4',
                ...
            },
            field: {
                // any field definition, for example:
                name: 'postalCode',
                as: 'text'
            }
        }
    ]
}

Fieldset

{
    as: 'fieldset',
    label: '',
    legendAttrs: {
        // html attributes passed to column legend element, for example:
        class: 'some-custom-legend-class'
    },
    fields: [
        // any field definition
        ... 
    ]
}

Customization

import { Factory } from 'vue-forminator'
import { LabelWrap, LabelBefore } from 'vue-forminator/lib/helpers'

const Forminator = Factory({
    config: {
        labelClass: 'control-label',
        inputClass: 'form-control',
        textInputClass: 'string or inputClass if not provided'
        numberInputClass: 'string or inputClass if not provided'
        emailInputClass: 'string or inputClass if not provided'
        selectClass: 'select',
        fieldClass: 'form-group',
        rowClass: 'row',
        columnClass: 'col',
        fieldsetClass: 'form-fieldset',
        fieldsetLegendClass: 'form-fieldset',
        requiredLabelClass: 'css to be applied to field which attrs.required is truthy'
    },
    Field, // Field component provider function
    inputs: {
        YourCustomInputComponent,
        // basic input components, i.e.
        Text,
        Checkbox,
    },
    fields: function({ ..inputs }) {
        return {
            'text': LabelBefore(Text),
            'boolean': LabelWrap(Checkbox)
        };
    }
})

FAQ

Q: What if i want to conditionaly show field

A: You can pass "falsy" value as a field definition

Testing

npm run test

TODO

  • [x] bulma.io config example
  • [x] bootstrap config example
  • [x] docs
  • [ ] imaskjs sample
  • [ ] vuelidate sample
  • [ ] schema validation in dev environment
  • [ ] create codesandbox.io examples