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

@ax-jstern/vue-form-json-schema

v2.9.7

Published

Vue package for using forms with JSON schema

Downloads

2

Readme

TODO: This readme is out of date and needs updated.

Vue Form JSON Schema

A JSON schema based form generator, bring your components!

Use any Vue component or HTML element!

There are no prebuilt components for you to puzzle your form together with. Instead you can use any component or element which emits an event, custom or native.

Note that essentially all Vue components that uses v-model emits an input (or similar) event. See Vue's guide for more info

Installation

Upgrading from v1? Check out the v2 release notes to see if and how migration affects you.

Install from npm

npm install vue-form-json-schema

Import to your app

import Vue from 'vue';
import VueFormJsonSchema from 'vue-form-json-schema';

Vue.component('vue-form-json-schema', VueFormJsonSchema);

Note if you're not using Webpack / Rollup and want to use the ESM version you need to import VueFormJsonSchema like this:

import VueFormJsonSchema from 'vue-form-json-schema/dist/vue-form-json-schema.esm.js';

Check out the demos or see a minimal example in the usage instructions to get started.

UMD

If you're using the UMD version you can find more examples in the examples folder of the github repo and the UMD demo below.

If you want to use vue-form-json-schema directly in a browser you can do so by using the UMD version. The UMD version autoinstalls the vue-form-json-schema component if Vue is found on the window. The entire module is also available on window.VueFormJsonSchema where the named exports such as for example vfjsFieldMixin can be accessed.

Hosted by unkpg

<script src="https://unpkg.com/vue-form-json-schema@latest/dist/vue-form-json-schema.umd.js"></script>

You can substite vue-form-json-schema@latest to a fixed version, such as [email protected]

Installed from npm

<script src="../node_modules/dist/vue-form-json-schema.umd.js"></script>

Demo

Note that all demos use Bootstrap styling, but no styling is included in this package and it is up to you what styles should be used.

Minimal demo

The least amount of configuration to render an input element.

Nested UI demo

Using Bootstrap classes to show how layout can be different for devices with different screen sizes. In this example two input fields will be wrapped inside a div with col-12 col-sm-6 classes. Try resizing your browser window too see it in action.

Conditional visibility and Animation demo

Sometimes a field should only be shown if a condition is met. Uses <transition> to provide animation.

Vue components demo

See how to use your own or third party Vue components in vue-form-json-schema.

Vue async loading of form

Loading the form from a backend? Check out this example.

Registration form with validation

A more complete example with validation and error messages

Registration form example with nested properties

The registration form above where the form model keys are nested under another key

UMD demos

All the examples above are replicated using the UMD version in the examples folder of this repo.

Online version of the first demo

Features

  • Supports any HTML element or Vue component
  • Small (32K uncompressed, 6.5K gzipped)
  • Standardized JSON schema for annotation and validation (by Ajv)
  • Layout is independent from data structure

Documentation

Gitbook

Usage

Basic example with one field

For using the UMD version, check out the examples folder where all the demos above are replicated using the UMD version

See demo

<template>
    <vue-form-json-schema
      v-model="model"
      :schema="schema"
      :ui-schema="uiSchema"
    >
  </vue-form-json-schema>
</template>

<script>
  export default {
    data() {
      return {
        // An object which holds the form values
        model: {},
        // A valid JSON Schema object
        schema: {
          type: 'object',
          properties: {
            firstName: {
              type: 'string',
            },
          },
        },
        // Array of HTML elements or Vue components
        uiSchema: [{
          component: 'input',
          model: 'firstName',
          // Same API as [Vue's render functions](https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth)
          fieldOptions: {
            class: ['form-control'],
            on: ['input'],
            attrs: {
              placeholder: 'Please enter your first name',
            },
          },
        }],
      };
    }
  };
</script>

Dependencies

Ajv

For form validation using JSON Schema and internal validation

Lodash

get, set and merge are used throughout the package. Bundle size is very important though and is always considered and so we heavily strip down lodash to only include the absolute necessities

Vue

Tested with v2.5.9 but will probably work on any version >= v2.4.0

TODO

  • Write tests
  • ~~Add i18n support~~
    • Added in 1.15.2 with options.ajv.locale setting
  • ~~Write this README~~
  • Use Ajv internally to validate:
    • vfs-global prop ui-schema
    • vfs-component prop ui-schema
  • ~~Write docs~~
  • ~~Publish with Gitbook~~