Native
Generate a form using JSON Schema and Vue.js
Install / Use
/learn @formschema/NativeREADME
FormSchema Native
Vue component form based on JSON Schema and Native HTML
Table of Contents
- Install
- Demo
- Usage
- Features
- Supported Keywords
- Irrelevant (ignored) Keywords
- FormSchema API
- Working with Async Schema
- Working with Vue Router
- Workind with JSON Schema $ref Pointers
- Data Validation
- Labels Translation
- Render Form Elements
- Custom Form Elements
- Descriptor Interface
- Usecases
- Contributing
- License
Install
npm install --save @formschema/native
Demo

Usage
<template>
<FormSchema :schema="schema" v-model="model" @submit.prevent="submit">
<button type="submit">Subscribe</button>
</FormSchema>
</template>
<script>
import FormSchema from '@formschema/native'
import schema from './schema/newsletter-subscription.json'
export default {
data: () => ({
schema: schema,
model: {}
}),
methods: {
submit (e) {
// this.model contains the valid data according your JSON Schema.
// You can submit your model to the server here
}
},
components: { FormSchema }
}
</script>
Features
- Keywords for Applying Subschemas With Boolean Logic
- Validation Keywords for Any Instance Type<br>
FormSchema uses:
- HTML input
textto render schema withtype: 'string' - HTML input
numberto render schema withtype: 'number' | 'integer' - HTML input
hiddento render schema withtype: 'null' - HTML input
checkboxto render schema withtype: 'boolean'
- HTML input
- Validation Keywords for Numeric Instances (number and integer)<br>
FormSchema parses keywords
maximum,minimum,exclusiveMaximumandexclusiveMinimumto generate HTML attributesmaxandmin. - Validation Keywords for Strings<br>
FormSchema parses keywords
maxLength,minLength,patternto generate HTML attributesmaxlength,minlengthandpattern. - Validation Keywords for Arrays
- Semantic Validation With "format"<br>
FormSchema uses:
- HTML input
dateto render schema withformat: 'date' - HTML input
datetime-localto render schema withformat: 'date-time' - HTML input
emailto render schema withformat: 'email' | 'idn-email' - HTML input
timeto render schema withformat: 'time' - HTML input
urlto render schema withformat: 'uri'
- HTML input
- String-Encoding Non-JSON Data
- Property dependencies and Schema dependencies
- Schema Re-Use With "definitions" (see JSON Schema $ref Pointers)
- Schema Annotations
Supported Keywords
- type is only supported string value. Array type definition is not supported.
- enum is used to render multiple choices input
- maximum, exclusiveMaximum, minimum and exclusiveMinimum are used to render numeric fields
- multipleOf is used to render the input attribute
step - maxLength, minLength, pattern and const are used to render string fields
- items, additionalItems, maxItems, minItems and uniqueItems are used to render array fields
- dependencies is used to implement Property dependencies and Schema dependencies
- contentEncoding
- contentMediaType<br>
- When
contentMediaTypeis equal totext/*, the HTML element<textarea/>is used for rendering - When
contentMediaTypeis not equal totext/*, the HTML element<input/>with attributes{ type: file, accept: contentMediaType }is used for rendering
- When
- title is used to render the input label
- description is used to render the input description
- default is used to define the default input value
- readOnly is used to render a field as an read-only input
Irrelevant (ignored) Keywords
Since FormSchema is just a form generator, some JSON Schema validation keywords are irrelevant:
- contains
- maxProperties
- minProperties
- patternProperties
- additionalProperties
- propertyNames
- not
- writeOnly
- examples
FormSchema API
Props
| Name | Type | Description
