crickford / vue-json-schema-form Goto Github PK
View Code? Open in Web Editor NEWVueJS library for generating forms from JSON schemas
License: MIT License
VueJS library for generating forms from JSON schemas
License: MIT License
Nice lib ❤️ , are you considering adding support to arrays at root level as well?
Use case:
When the json schema root type is array
we should be able to have add/remove whole blocks of properties, same as right now it's working when a sub-type is array of objects
Example schema
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/root.json",
"title": "root",
"type": "array",
"items": {
"title": "Person",
"type": "object",
"$id": "#/items",
"properties": {
"firstName": {
"type": "string",
"title": "First Name",
"description": "The person's first name.",
"example": "John"
},
"lastName": {
"type": "string",
"title": "Last Name",
"description": "The person's last name.",
"example": "Doe"
},
"nickNames": {
"type": "array",
"title": "Nicknames",
"items": {
"type": "string",
"example": "j-dough"
}
},
"address": {
"type": "object",
"title": "Address",
"properties": {
"lineOne": {
"type": "string",
"title": "Address line 1",
"example": "Address line 1"
},
"lineTwo": {
"type": "string",
"title": "Address line 2",
"example": "Address line 2"
},
"postalCode": {
"type": "string",
"title": "Postal code",
"example": "Postal code"
}
}
},
"age": {
"title": "Age",
"description": "Age in years which must be equal to or greater than zero.",
"type": "integer",
"minimum": 0
}
},
"required": [
"firstName"
]
}
}
Are there any plans to support remote schemas? I am new to Vue so if it's already covered please let me know.
When I try to remove 1st item in object array, 2nd item is removed instead of 1st one in schema form.
however, I checked form-data through the script, the result is right.
I attached an image and JsonSchema below.
{
"title": "Person",
"type": "object",
"properties": {
"firstname": {
"type": "string",
"title": "First Name"
},
"testArray": {
"type": "array",
"title": "TESTARRAY",
"items": {
"type": "object",
"properties": {
"item1": {
"type": "number",
"title": "item1"
},
"item2": {
"type": "number",
"title": "item2"
}
}
}
}
}
}
It would have been very handy to be able to display the value of the default property in Json Schema in the form when generated. E.g. in TextElement.vue if you change :value="value" to :value="schema.default != null ? schema.default : value" (if this doesn't cause other issues, I haven't deep dived into your source code). Or is there some other way to achieve this that I've overlooked?
I am trying to generate a form which can have multiple recursive fields. I have used https://codepen.io/crickford/pen/ZmJqwd this demo (I am not using any custom component). Whenever i am using "$ref" it ignores it.
My Json-schema is valid. Even if i replace the following schema in codepen i don't get expected result, where as it is giving me by editing schema property of the source in this link http://www.alpacajs.org/docs/api/recursive-references.html
I don't know where am I mistaking !! At least in codepen attached schema code should work.
Kindly guide me or share working demo fiddle with me. Thanks in advance.
Here is my schema:
{ "type": "object", "title": "", "properties": { "Namespace": { "type": "string", "title": "Namespace ", "attrs": { "placeholder": "Namespace", "title": "Please enter Namespace" } }, "Name": { "type": "string", "title": "Display Name : ", "attrs": { "placeholder": "Display Name", "title": "Please enter Display name" } }, "SubSteps": { "type": "array", "title": "SubSteps", "items": { "type": "object", "title": "Sub step", "$ref": "#/definitions/SubSteps" } } }, "definitions": { "SubSteps": { "type": "object", "title": "SubStep item", "properties": { "Namespace": { "type": "string", "title": "Namespace ", "attrs": { "placeholder": "Namespace", "title": "Please enter Namespace" } }, "Name": { "type": "string", "title": "Display Name : ", "attrs": { "placeholder": "Display Name", "title": "Please enter Display name" } }, "SubSteps": { "type": "array", "title": "SubSteps", "items": { "type": "object", "title": "Sub step", "$ref": "#/definitions/SubSteps" } } } } }, "required": [ "Name" ] }
We are currently writing an adaption of a twig frontend written in PHP generating forms using Symfony/FromBuilder. We found a library that converts Symfony forms into JSON Schema but the resulting schema is not exactly what this project needs. Are there any matching transformers out there known to you guys? Thanks in advance, Jan
First of all , thank you for providing such an excellent project.
In actual use, we need to make some changes based on your project. But, expect how to run local demo, no packaging instructions were found.
So, could you please guide how to generate a new version after personalized modification ?
Thanks!
@crickford Using the advance demo, i am trying to use the rating component in a nested object. The default input box shows instead of the rating component. It appears only root object items are supported, any thoughts to nested obects?
Looks like it the code processing custom component is SchemaForm.vue:
<template v-for="(property, key) in schema.properties"> <slot :name="key" :item="{key: key, schema: property, value: items[key], update: updateValue}"> <component :is="element" :key="key" :schema="property" :value="items[key]" @input="updateValue($event, key)"></component> </slot> </template>
Schema Example:
{ "type": "object", "properties": { "test": { "type": "object", "properties" : { "teststring": { "type": "string", "title": "Test String" }, "rating": { "type": "number", "title": "Rating", "minimum": 0, "maximum": 5 } } } } }
I want to make schema-form has stored data so that user can edit form-data whenever they want.
However once schema-form is created, I can't bind data through the method. ( I get the data from server through axios, and try to bind when vue page is created.)
plz check example below.
<schema-form :schema="schema" v-model="obj" @submit="handleSubmit()" />
data () {
return {
schemaIsValid: true,
schema: baseSchema,
obj: {
"firstName": "11111",
"nickNames": [
{
"url": "111111111111",
"title": "1111111111111"
}
]
},
}
<schema-form :schema="schema" v-model="obj" @submit="handleSubmit()" />
<button type="button" class="button" @click="UpdateData()">Update form Data
data () {
return {
schemaIsValid: true,
schema: baseSchema,
obj: {}
}
},
methods: {
handleSubmit() {
console.log(JSON.stringify(this.obj, null, 2))
}
,UpdateData() {
this.obj = baseData;
}
}
<schema-form :schema="schema" v-model="obj" @submit="handleSubmit()" />
data () {
return {
schemaIsValid: true,
schema: baseSchema,
obj: {},
}
},
created() {
this.$http
.get(URL,{ headers: { 'Content-Type' : 'application/json'}})
.then( res => {
this.obj = JSON.parse(res.data..obj);
}
,function() {
console.log('failed')
});
},
check image below.
as you can see in the image, data is binded after axios or click event, but the form is still empty and the data is removed when click submit button.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.