Giter Site home page Giter Site logo

wotamann / vuetify-form-base Goto Github PK

View Code? Open in Web Editor NEW
231.0 14.0 63.0 8.89 MB

Schema-based Form Generator - Vue.js 2.0 Component based on Vuetify 2.0

Home Page: https://wotamann.github.io/vuetify

JavaScript 89.53% HTML 0.25% Vue 10.19% Shell 0.03%
vue vuetify javascript form generator reactive schema-design vue-component vuetify-control

vuetify-form-base's Introduction

Documentation

Updated Documentation at Gitbook


Vuetify-Form-Base

Imagine you get Data as JS-Object and you have to create an editable Form.

Model: {
	name: 'Stoner',
	position: 'Admin',
	tasks: [
		{ 
		  done: true,
		  title: 'make refactoring' 
		},
		{ 
		  done: false,
		  title: 'write documentation'  
		},
		{ 
		  done: true,
		  title: 'remove logs'  
		}        
	]        
}

Normally you have to flatten the Data-Structure and map all to an appropriate Format. Then you have to define a HTML-Form and animate it with your Data.

With Vuetify-Form-Base create a Schema Object with the same Structure as your Data.

Schema: {
	name: { type:'text', label:'Name' },
	position: { type:'text', label:'Position' },
	tasks: { 
		type: 'array',
		schema: { 
			done:{ type:'checkbox', label:'done', col:3}, 
			title:{ type:'text', col:9 }
		} 
	}
}  

and you will get a working Form.

Form

If you have to generate Forms or you have to edit Data presented as JSON- or JS-Objects, then take a closer look at Vuetify-Form-Base and try it. It can make your work much easier and save your time. This Form Generator works as Vue.js 2.0 Component and can simplify your Work by automatically creating Forms, based on your Schema-Definition.

Furthermore if you don't define a Schema, then Vuetify-Form-Base tries to generate a schema automatically. This works if the Data Values are of Type 'string', 'number' or 'bool'.

Vuetify-Form-Base uses the well known and excellent Component Framework Vuetify 2.0 to style and layout your Form. Vuetify Controls have a clear, minimalistic design and support responsive Design. If necessary add specific layouts by using the implemented Vuetify Grid System.


Demo

Read Documentation

and start here

Here you can see a Demo with Key-Examples

or

Clone or download this Project, change current directory to ./vuetify-form-base/example and then run

npm install

npm run serve

or

Download and open this HTML-File in your Browser

or

Play with Fiddle

or

Copy this HTML File with CDN

<html>
	<head>
	  <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
	  <link href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet">
	  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet">
	  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
	</head>	
	<body>
		<div id="app">
		<v-app>
		  <v-main>
			<v-container>
				<v-form-base :col="{cols:12, sm:6, md:3 }" :model="model" :schema="schema" @input="log" />
			</v-container>
		  </v-main>
		</v-app>
		</div>

		<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.js"></script>
		<script src="https://unpkg.com/vuetify-form-base"></script>
		<script>
		new Vue({
			el: '#app',
			vuetify: new Vuetify(),
			components: { vFormBase },
			data () {
				return {      
				  model: {
					text: 'Base',
					password: 'abcdefgh',
					checkbox:true,
					file: [] // array of File objects
				  },     
				  schema: {
					text: 'text', // shorthand for ->  text: { type:'text', label:'text' }                   
					password: { 
					  type: 'password',
					  clearable: true,
					  solo:true,
					  class:'mx-2 mt-2'
					},			  
					checkbox:'checkbox',
					file: { 
					  type: 'file', 
					  label: 'Images', 
					  showSize:true,
					  counter:true
					}
				  }
				}
			},
			methods:{
				log(v){ 
					console.log(v) 
				}
			}
		})
		</script>
	</body>
</html>

Intro

vuetify-form-base comes as a singular File. It is a Vue Component and can easily integrated into any Vue Project.

<v-form-base :model="myModel" :schema="mySchema" @input="handleInput" />

<!-- ident but deprecated  -->
<v-form-base :value="myModel" :schema="mySchema" @input="handleInput" />

The Schema-Object has the same Structure as the Model-Object. Create a Schema by copying the Model-Object and replace the Values of the Model-Object by Definitions for your your Schema. This corresponding Schema-Object defines type, layout and functional behaviour of the Controls in your Form.

Form Example


The Component Framework Vuetify 2.0 styles your Form. The Controls have a clear design, but don't worry if you need more you can change Style and Layout. For more Details see Section Style with CSS

Autogenerated Schema

If you don't define a Schema, then Vuetify-Form-Base tries to generate a schema automatically. But this works only if the Model Values are of Type 'string','number' or 'bool'.

Defined Schema

Based on an existing Model vuetify-form-base generates a full editable Form using defined Schema. Layout and Functionality are defined in a Schema-Object, which has the same Property structure as the Model-Object. Your Data-Object keeps full reactive and any Input or Change in your Form triggers an Event too.

If you have a deep nested Model-Object including any Array-Structure you can direct work on it. There is no need to flatten or modify your Data Presentation.

Form Example

Changing any Field in the Form gives you a reactive Result in your Model-Object. Furthermore you can synchronize two or more Forms by using same Model-Object.

If you want a Partial-Form which displays only parts of your Data.Object, then link a property of your Data-Object to your vuetify-form-base Component.

And if necessary you can also build a Form in Form by using Slots.


Events in 'v-form-base'

Use the v-on directive to listen to Events for

'Focus', 'Input', 'Click', 'Blur', 'Resize', 'Intersect', 'Mouse' and 'Swipe'.

'Change' will catch 'Input' and 'Click'.

'Watch' will listen to 'Focus', 'Input', 'Blur' and 'Click'.

'Update' will catch all Events.

<!-- No ID defined -->
<v-form-base 
  :model="myModel"
  :schema="mySchema"
  @input="handleInput"
  @resize="handleResize"
/>

<!-- ID defined  -->
<v-form-base 
  id="form-base-person"
  :model="myModel"
  :schema="mySchema"
  @input:form-base-person="handleInput"
  @blur:form-base-person="handleblur"
/>

Supported Attributes in 'v-form-base'

<v-form-base 
  id="my-form-base"
  :model="myModel"
  :schema="mySchema"
  :row ="rowAttributesForLayoutControl"
  :col = "globalColDefinition"  
  @input:my-form-base="handleInputOrOtherEvents"
/>
<!-- deprecated -->
<v-form-base 
  :value= "myModel"
  :flex = "globalColDefinition"  
/>

Supported Controls - Vuetify Input & Controls


Text-Field

  // Textfield - Text: 
  schema: { ctrl: 'text' }  // shorthand definition
  
  schema: { 
    ctrl: { type:'text', ...} 
  }
  // Textfield - Password: 
  schema: { ctrl: 'password' }
  
  schema: { 
    ctrl: { type:'password', ...} 
  }
  // Textfield - Email:  
  schema: { ctrl: 'email' }
  
  schema: { 
    ctrl: { type:'email', ...} 
  }
  // Textfield - Number:  
  schema: { ctrl: 'number' }
	
  schema: { 
    ctrl: { type:'number', ...} 
  }

  // Use most of Attributes from <v-text-field>
  schema: { 
    ctrl: { 
      type:'text', 
      label:'Search', 
      hint:'Books', 
      prependIcon:'search', 
      clearable:true } 
    }

More Informations to Vuetify-Textfield Attributes find here.


Access native Type of HTML-INPUT

Prop 'ext' in combination with Type:'text' make the native HTML Input Type accessable.

mySchema:{    
  range:{ 
    type:'text', 
    ext:'range' 
  },
  color:{ 
    type:'text', 
    ext:'color',
    prependIcon: 'palette', 
    label:'Color'
  },    
  date:{ 
    type:'text', 
    ext:'date', 
    locale:'en',
    prependIcon: 'event', 
    label:'Date'
  },
  time:{ 
    type:'text', 
    ext:'time', 
    format:'24h',
    prependIcon: 'timer', 
    label:'Time'
  }
}

File-Input:

schema: { ctrl: 'file', ... }
schema: { ctrl: { type:'file', ...}, ... }

More Informations to Vuetify File-Input find here.


Textarea:

schema: { ctrl: 'textarea', ... }
schema: { ctrl: { type:'textarea', ...}, ... }

More Informations to Vuetify Textarea find here.


Checkbox, Radio or Switch:

// Checkbox
schema: { ctrl: 'checkbox', ... }
schema: { ctrl: { type:'checkbox', ...}, ... }

// Radio: 
schema: { ctrl: { type:'radio', ...}, ... }

// Switch: 
schema: { ctrl: 'switch', ... }
schema: { ctrl: { type:'switch', ...}, ... }

More Informations to Vuetify Selection-Controls find here.


Slider

// Slider: 
schema: { ctrl: 'slider', ... }
schema: { ctrl: { type:'slider', ...}, ... }

More Informations to Vuetify Sliders find here.


Icon

// Icon: 
schema: { ctrl: 'icon', ... }
schema: { ctrl: { type:'icon', ...}, ... }

More Informations to Vuetify Icons find here.


Image

// Image: 
schema: { ctrl: 'icon', ... }
schema: { ctrl: { type:'img', src:'...', ...}, ... }

More Informations to Vuetify Icons find here


Button

// Button: 
schema: { ctrl: 'btn', ... }
schema: { ctrl: { type:'btn', ...}, ... }

More Informations to Vuetify Buttons find here.

Button-Group

// Button Group: 
schema: { ctrl: 'btn-toggle', ... }
schema: { ctrl: { type:'btn-toggle', ...}, ... }

More Informations to Vuetify Button Groups find here.


Select, Combobox, Autocomplete

Select Data from Array defined in Schema

// Select:
schema: { ctrl: 'select', ... }
schema: { ctrl: { type:'select', items:['1','2'] }, ... }

More Informations to Vuetify Select find here.

// Combobox:
schema: { ctrl: 'combobox', ... }
schema: { ctrl: { type:'combobox', items:['1','2']}, ... }

More Informations to Vuetify Combobox find here.

// Autocomplete:
schema: { ctrl: 'autocomplete', ... }
schema: { ctrl: { type:'autocomplete', items:['1','2']}, ... }

More Informations to Vuetify Autocomplete find here.


List and Treeview

Select Items from an Array in your Model

// List: Edit  
schema: { ctrl: 'list', ... }
schema: { ctrl: { type:'list', ...}, ... }

More Informations to Vuetify List-Item-Groups find here.

// Treeview: 
schema: { ctrl: 'treeview', ... }
schema: { ctrl: { type:'treeview', ...}, ... }

More Informations to Vuetify Treeview find here.


Model-Array

  // Array: 
  model:{
    ctrlArray:[
      { idx:1, ctrl:'A'},
      { idx:2, ctrl:'B'},
      { idx:3, ctrl:'C'}
    ]
  }
	schema: { 
    ctrlArray: { 
      type:'array',
      // optional define key for array removing 
      key:'idx' // or ['idx','ctrl']
      // define schema of your items in array
      schema: { ctrl: 'text' }
    }, 
	}

Group Controls

  // Grouping
  model:{
    group1:{ a: 'A', b: 'B', c: 'C' }
    group2:{ a: 'A', b: 'B', c: 'C' }
  }
	schema: { 
    group1: { 
      type:'group',
      schema: { a:'text', b:'text', c:'text' }
    }, 
    group2: { 
      type:'group',
      schema: { a:'text', b:'text', c:'text' }
    }, 
	}

See more under Example 'Group Controls'


Color - Pickers, Menu & Native Implementation

// Color Picker: 
schema: { ctrl: 'color', ... }
schema: { ctrl: { type:'color', ...}, ... }

// Textfield with linked Color Menu
color:{ 
  type:'color', 
  ext:'text',
  prependIcon:'palette', 
  label:'Color'
}    
// Color - Native HTML <Input type="color" /> 
color:{ 
  type:'text', 
  ext:'color',
  prependIcon:'palette', 
  label:'Color'
}    

More Informations to Vuetify Color-Pickers find here.

Date|Month - Pickers, Menu & Native Implementation

// Date Picker: 
schema: { ctrl: 'date', ... }
schema: { ctrl: { type:'date', ...}, ... }

// Textfield with linked Date Menu
date:{ 
  type:'date', 
  ext:'text',
  locale:'en',
  prependIcon:'event', 
  label:'Date'
}

// Textfield with linked Month Menu
date:{ 
  type:'date', 
  ext:'text',
  typeInt:'month', 
  locale:'en',
  prependIcon:'event', 
  label:'Date'
}

// Date - Native HTML <Input type="date" />
date:{ 
  type:'text', 
  ext:'date', 
  locale:'en',
  prependIcon: 'event', 
  label:'Date'
}

More Informations to Vuetify Date-Pickers find here.

Time - Pickers, Menu & Native Implementation

// Time Picker: 
schema: { ctrl: 'time', ... }
schema: { ctrl: { type:'time', ...}, ... }

// Textfield with linked Time Menu
time:{ 
  type:'time', 
  ext:'text', 
  format:'24h',
  prependIcon: 'timer', 
  label:'Time',    
  menu:{ closeOnContentClick:false, nudgeRight:200, maxWidth:'290px', minWidth:'290px' }
}

// Time  - Native HTML <Input type="time" />
time:{ 
  type:'text', 
  ext:'time', 
  format:'24h',
  prependIcon: 'timer', 
  label:'Time'
}

More Informations to Vuetify Time-Pickers find here.

See Example under Section 'Date, Time, Color as native HTML-Type, Menu and Pickers'


Installation

For proper working you need a Vue.js Project with Vuetify 2.0 installed. Get started with Vuetify, the world’s most popular Vue.js framework for building feature rich, blazing fast application here.

INFORMATION: Vue-Loader doesn't autoload components, because Vuetify-Form-Base use

<component is="my-component" />

and therefore Components must be manually imported. More information about dynamic components is in the official Vue documentation

After successful installation of a Vue 2.6 Project with Vuetify 2.0

npm install vuetify-form-base --save

vuetify-form-base is a Vue.js single-file component with a .vue extension and you can use it like any Vue-Component.

In order for your application to work properly, you must wrap it in a v-app component. This component is required and can exist anywhere inside the body, but must be the parent of ALL Vuetify components. v-main needs to be a direct descendant of v-app.

Information: since Vuetify 2.3.10 "v-content" is named "v-main"

How to manually import components and directives

Steps to import

  1. Go to the file src/plugins/vuetify.js
  2. Import the necessary components and directives used by vuetify-form-base:
  • Components
    • VRow
    • VCol
    • VTooltip
  • Directives
    • Ripple
    • Intersect
    • Touch
    • Resize
  1. After this, the library will be successfully imported to your Vue file, and no errors on the console should appear.
  2. If a new error appears on the console, it means component you are using is not imported. See the name of the component on the console and add tot he plugin file.

Example file from src/plugins/vuetify.js

import Vue from 'vue';
import Vuetify, {
    VRow,
    VCol,
    VTextField,
    VTooltip,
    VCheckbox,
    VSelect,
} from 'vuetify/lib';
import { Ripple, Intersect, Touch, Resize } from 'vuetify/lib/directives';

Vue.use(Vuetify, {
    components: { VRow, VTooltip, VCol, VTextField, VCheckbox, VSelect },
    directives: { Ripple, Intersect, Touch, Resize },
});

export default new Vuetify({});

This example shows how to import the needed components and directives to use the vuetify-form-base and some basic components like VTextField, VCheckbox, VSelect.

Quickstart with VUE-File

<!-- exampleFile.vue -->
<template>
  <v-app>
  <!-- Since Vuetify 2.3.10 "v-content" is named "v-main"  -->
    <v-main>
      <v-container fluid>
        <v-form>
          <v-form-base :model="myModel" :schema="mySchema" @input="handleInput"/>
        </v-form>
      </v-container>   
    </v-main>
  </v-app>
</template>
import VFormBase from 'vuetify-form-base';  

export default {	
  components:{ VFormBase },
  data () {
    return {
      myModel: {
        name: 'Jumo',
        password: '123456',
        email: '[email protected]',
        checkbox: true,
        select: 'Jobs',
      },   
      mySchema: {
        name: { type: 'text', label: 'Name' },
        password: { type: 'password', label: 'Password' },
        email: { type: 'email', label: 'Email' },
        checkbox: { type: 'checkbox', label: 'Checkbox' },
        select: { type: 'select', label: 'Select', items: ['Tesla', 'Jobs', 'Taleb'] }
      }
    }
  },
  methods:{
    handleInput(val){
      console.log(val) 
    }
  }
}

and you will get a full editable Form based on your schema and filled with your Model-Object.

Basic Form

INFORMATION:

Properties in 'myModel' without corresponding Prop in 'mySchema', are ignored and keep untouched, but a initial warning will be logged to console


Example displaying nested Data-Object

In Reality sometimes you will have deep nested objects or arrays, which should be edited. vuetify-form-base works for you and flatten internally this nested object and build a plain Form.

myValue: {
  name: 'Base',
  controls:{
    selection:{
      select: 'Tesla',
      selectM: ['Jobs'],
    },
    switch: [ true,false ],
    checkbox: [ false, true, { 
      checkboxArray: [ true, false ]}
    ]
  }       
},

mySchema: {
  name: { type: 'text', label: 'Name'},
  controls:{
    selection:{
      select: { type: 'select', label: 'Select', items: ['Tesla', 'Jobs', 'Taleb'] },        
      selectM: { type: 'select', label: 'M-Select', multiple:true, items: ['Tesla', 'Jobs', 'Taleb']}
    },
    switch: [ 
      { type: 'switch', label: '1' }, 
      { type: 'switch', label: '2' } 
    ],
    checkbox: [
      { type: 'checkbox', label: 'A' },
      { type: 'checkbox', label: 'B' }, 
      { checkboxArray: [
        { type: 'checkbox', label: 'C-A', color:'red' },
        { type: 'checkbox', label: 'C-B', color:'red' }
      ]}  
    ],
  }
}

Form Example


Example editing Data-Arrays

For editing arrays use the type 'array' and define an nested 'schema' property.

    mySchema: {
      tasks: {
        type: 'array',
        schema: { 
          done: { type: 'checkbox'  }, 
          title: { type: 'text' }
        }
      }  
    }

Type Array - Schema object

    myValue: {      
      tasks: [
        {
          idx:0,
          done: true,
          title: 'make refactoring'
        },
        {
          idx:1,
          done: true,
          title: 'write documentation'
        },
        {
          idx:2,
          done: true,
          title: 'remove logs'
        }
      ]
    },
    mySchema: {
      tasks: {
        type: 'array',
        // 'key' is optional.
        // For working on arrays (ie removing) define a key
        // IMPORTANT: don't use an editable key (because of permanent re-iteration on change) 
        key:'idx',
        schema: { 
          done: { type: 'checkbox', label: 'Ok', col: 3 }, 
          title: { type: 'text', col: 8 },            
        }
      }
    }

Form Example


Dynamic Schema

IF you want Schema Properties to be changed dynamic, then you must make a computed Schema Object.

This Example turns the Radio Layout from Column to Row on Resizing to Layout-Size medium or greater.

data () {
  return {
    myModel:{
      radio: 'A',
    }, 
  }
},
//  dynamic Schema with computed 
computed:{
  mySchema() { 
    return {       
      radio: { type: 'radio', row: this.row, options:['A','B'] }
    }  
  },
  row () { return this.$vuetify.breakpoint.mdAndUp }
}

Vuetify Display, Typography and Spacing

Integrate Vuetify-Display and Layout behaviour by using the Schema-Property 'class':

    mySchema: {
      name: { type: 'text', class:'title d-flex d-sm-none ml-4 pa-1 float-left' },
    }

More Info at Vuetify Display:

More Info at Vuetify Typography:

More Info at Vuetify Spacing:

More Info at Vuetify Float:

See Example under Section 'Display, Typographie and Layout'


Vuetify Grid

Integrate Vuetify-Grid behaviour by setting the Form-Base Property 'col':

Default Form-Base Definition

<!-- object declaration -->
<form-base :col="{ cols:12, sm:8, md:6, lg:4 }" ... />
<!-- ident but deprecated -->
<form-base :flex="{ xs:12, sm:8, md:6, lg:4 }" ... />  

<!-- default grid -->
<form-base :col="{ cols:12 }" ... />
<form-base :col="{ cols:'auto' }" ... />

<!-- or shorthand for {cols:12 }  -->
<form-base :col=12 ... />
<form-base :col="12" ... />
<!-- ident but deprecated -->
<form-base :flex="12" ... />

<!-- NEW 'row' Attribute 
set v-row and is a wrapper component for v-col. It utilizes flex properties 
to control the layout and flow of its inner columns. Standard gutter can be
reduced with the dense prop or removed completely with no-gutters

see -> https://vuetifyjs.com/en/components/grids/ 
-->
<form-base :row="rowAttribute" :col="12" ... />
const rowAttribute = { justify:'center', align:'center', noGutters:true } 

Schema-Definition (overrules Form-Base Definition)

Get individual Grid-Control by using Schema-Properties 'col', 'offset' and 'order'.

mySchema: {      
  name1: { type: 'text', col: 4, offset: 2, order: 1 },
    // col: 4     // shorthand for col: { cols:4 }
    // offset: 2  // shorthand for offset: { offset:2 }
    // order: 1   // shorthand for order: { order:1 }
  },
  name2: { 
    type: 'text', 
    col: { cols:12, sm:6, md:4, lg:3, xl:2 }, 
    offset:{ offset:0, sm:1, md:2 }, 
    order:{ order:0, sm:1, md:2 } 
  }
}

More Info at Vuetify Grid:


Link & Synchronize

Forms can be linked together using the same Model-Object. Changes in one Form are synchronized and reflected in the other Form.

	<v-form-base :model="myValue" :schema="mySchema" />
  
	<v-form-base id="form-sync" :model="myValue" :schema="mySchema" />

From 'cebab-case' to 'camelCase' in Vuetify-Controls API

Use Vuetify Controls API: Props in Vuetify-Controls in kebab-case must be converted to camelCase in Schema-Definition.

  mySchema: { 
    name: { type:'text', prependIcon:'menu', backgroundColor:'red' }  
  }

maps to

	<v-text-field prepend-icon="menu" background-color="red"></v-text-field>

Schema

<v-form-base :model="myValue" :schema="mySchema" />

<v-form-base 
  id="form-id" 
  :model="myValue" 
  :schema="mySchema" 
  :col="12" 
  :change:form-id="myEventHandler"
/>

Schema is an Object, which defines and controls the behavior of your Form. Each Key in your Schema-Object should reflect a Key from your Data-Object.

data () {
  return {
    myValue:{
      name: 'Base'  
    }, 
    mySchema:{
      name: 'text' // shorthand for name: { type:'text', label:'name' }  
    }
  }
}

The next example shows a more complex Schema:

    // Partials Functions for Rules
    const minLen = l => v => (v && v.length >= l) || `min. ${l} Characters`
    const maxLen = l => v => (v && v.length <= l) || `max. ${l} Characters`
    const required = msg => v => !!v || msg
    const validEmail: msg => v => /.+@.+\..+/.test(v) || msg
  
	  // Destruct value from obj and return a modified value! 
    const toUpper = ( {value} ) => typeof value === 'string' ? value.toUpperCase() : value 

    export default {
    
      components: { VFormBase },

      data () {
        return {
          // model
          myModel: {
            name: 'Base',
            password: '123456',
            email: '[email protected]'
          },
          // schema
          mySchema: {
            name: { 
              type: 'text', 
              label: 'Name', 
              hint:'Converts to UpperCase'
              toCtrl: toUpper, 
              fromCtrl:toUpper,
              rules: [ required('Name is required<>) ] 
              col: 12, 
            },
            password: { 
              type: 'password', 
              label: 'Password', 
              hint:'Between 6-12 Chars', 
              appendIcon: 'visibility', 
              counter: 12, 
              rules: [ minLen(6), maxLen(12) ], 
              clearable: true, 
              col: 12 
            },
            email: { 
              type: 'email', 
              label: 'Email', 
              rules: [ validEmail('No valid Email'), required('Email is required<>) ], 
              col: 12 
            }
          }
        }
      }

    }

**Available Properties in Schema **

For more Schema-Properties see Vuetify Controls API

schema:{
  
  type: string            // text, password, email, file, textarea 
                          // radio, switch, checkbox, slider,
                          // select, combobox, autocomplete, 
                          // array, list, treeview
                          // icon, btn, btn-toggle 
                          // date, time, color

  ext: string             // access to native HTML-Input Type 

  sort: num               // use simple order to display items 

  col:   num or object    // See Vuetify Grid
  flex:  num or object    // DEPRECATED 
  order: num or object    // use Vuetify-Grid  
  offset: num or object   // See Vuetify Grid

  label string,           // label of item    
  placeholder: string,    // placeholder 
  hint: string,           // additional Info  
  tooltip: string | bool | object // show tooltip - use Slots for individual text

  color: string
  backgroundColor:string
  class: string,            // inject classnames - schema:{ name:{ css:'small'}, ...  }
    
  mask: string,           // regex to control input  

  multiple: bool,         // used by type: select, combobox, autocomplete    
  required: bool,         // need an input value
  hidden: bool,           // hide item - set from another item
  disabled: bool,         
  readonly: bool,          
        
  appendIcon: icon        // click triggers event with icon-location
  prependIcon: icon       // click triggers event with icon-location

  items: array            // ['A','B'] used by type: select, combobox, autocomplete   
  options: array,         // ['A','B'] used by type:radio
  rules: array of Fn      // [ value => true || false, ... ]
  
  // must return a (modified) value!!
  toCtrl: function,       // ( {value, obj, data, schema} ) => value	
  fromCtrl: function,     // ( {value, obj, data, schema} ) => value
}

Events

We can use the v-on directive to listen to vuetify-form-base events 'focus', 'input', 'click', 'blur', 'change', 'watch', 'mouse', 'display', 'intersect', 'resize', 'swipe', 'update' and run some Code when they’re triggered.

This Example use the Default ID and listen all events with 'update':

    <!-- HTML -->
    <v-form-base :value= "myValue" :schema= "mySchema" @update= "update" />

The next Code has the Custom ID 'form-base-simple'. In this case your v-on Directive must append the Custom ID like @update:form-base-simple:

    <!-- HTML -->
    <v-form-base 
      id = "form-base-simple" 
      :value= "myValue" 
      :schema= "mySchema" 
      @update:form-base-simple= "update" 
    />

You can listen to one or more Events

  <!-- HTML -->
  <!-- compose Listener to one or more of following Events: -->
  <v-form-base 
    :model= "myValue" 
    :schema= "mySchema" 
    
    @click= "log"
    @input= "log"
    @change="log"    // input|click
    @watch= "log"    // focus|input|click|blur
    @focus= "log"
    @blur=  "log"        
    @mouse= "log"    // mouseenter|mouseleave  
    @display= "log"  // resize|swipe|intersect 
    @intersect="log" // intersect - https://vuetifyjs.com/en/directives/intersect
    @resize= "log"
    @swipe=  "log"   // touch events        
    @update= "log"   // catch all events    
  />      

The Event-Signature:

    change( {  on, id, key, value, params, obj, data, schema, parent, index, event } ){
      // destructure the signature object 
    }
on -        Trigger Name  // focus|input|blur|click|resize|swipe|update 
id -        Formbase-ID
key -       key of triggering Element
value -     value of triggering Element
obj -       triggering Element { key, value, schema } 
event -     the native trigger-event if available 
params -    params object if available { text, x, y, tag, model, open, index }    
index -     index of array of schemas  
data -      Data-Object
schema -    Schema-Object
parent -    Formbase-Object - if available 

Example: Use 'Change' Event to change Visibility on Password Element

    <!-- HTML -->
    <v-form-base :model="myValue" :schema="mySchema" @change="change">
    ...

    mySchema: {
      firstPassword:{ type:'password', appendIcon:'visibility', .... }
    }
    
    ...
    
    change ({ on, key, obj, params }) {
      // test event is 'click' and comes from appendIcon on key 'firstPassword'
      if (on == 'click' && key == 'firstPassword' && (params && params.tag) == 'append') {         
        // toggle icon
        obj.schema.appendIcon = obj.schema.type === 'password'? 'lock': 'visibility'
        // toggle visibility 
        obj.schema.type = obj.schema.type === 'password'? 'text': 'password'
      }
    }

Slots

Use Slots to pass Header and Footer into a Control. If necessary replace Controls by Slots. Any slot could be a v-form-base component itself.

   <!-- FORM-BASE-COMPONENT -->
    <v-form-base id="form-base-css" :model="myValue" :schema="mySchema" >
      <!-- FORM SLOT -->
      <h4 slot="form-base-css-top" class="slot">
        Top Slot of 'Form'
      </h4>
      <h4 slot="form-base-css-bottom" class="slot">
        Bottom Slot of 'Form'
      </h4>  
      <!-- KEY SLOTS -->
      <h4 slot="slot-top-key-name" class="slot">
        Slot at Top of Key 'Name'
      </h4>
      <h4 slot="slot-item-key-password" class="slot">
        Slot replaces Key 'Password'
      </h4>
      <h4 slot="slot-bottom-key-email" class="slot">
        Slot at Bottom of Key 'Email'
      </h4>
      <!-- TYPE SLOTS -->
      <h4 slot="slot-top-type-btn-toggle" class="slot">
        Slot at Top of Type 'Btn-Toggle'
      </h4>
      <h4 slot="slot-bottom-type-btn" class="slot">
        Slot at Bottom of Type 'Btn'
      </h4>
      <h4 slot="slot-top-type-radio" class="slot">
        Slot at Top of Type 'Radio'
      </h4>
      <!-- TOOLTIP SLOTS -->
      <div
        slot="slot-tooltip"
        slot-scope="slotProps"
      >
        Tooltip-Slot: {{ slotProps.obj.schema.tooltip }} has value '{{ slotProps.obj.value || 'undefined' }}'
      </div>
      <!-- TOOLTIP SLOT -  New Syntax VUE 2.6.0 -->
      <!-- <template v-slot:slot-tooltip="slotProps">
         {{ slotProps.obj.schema.tooltip }} with Value: {{ slotProps.obj.value }}
      </template> -->
    </v-form-base>

Try CSS & Slots in Example

Slots in Blue


Form Validation

If you need Form Validation you have to wrap v-form-base with v-form and take the reference of v-form for working on.

    <!-- HTML -->    
    <v-form ref="form" v-model= "formValid" lazy-validation>
      <v-form-base :model= "myValue" :schema= "mySchema" @update= "update"/>
    </v-form>
    <!-- JS -->
    validate () {
      this.$refs.form.validate()
    },

    resetValidation () {
      this.$refs.form.resetValidation()
    },

Try Form with Rules and Validation in Example


Style with CSS

Customize your vuetify-form-base component using CSS-Classnames

Try CSS, SLots, Tooltips & Buttons in Example

IMPORTANT:
Don't use <style scoped> in parents component, because scoped definitions are inside the child component not accessable

Formbase - Default ID

#form-base is the default ID of your component. If you need different CSS for two or more forms in the same parent component, then change default value by setting a different ID for each component and use this new ID. Using a 'custom-id' you have to modify the event-binding to @update:custom-id = "update"

- Default ID

    <!-- HTML-Template -->   
    <v-form-base @update= "update" />  
    #form-base {...} 

- Custom-ID

    <!-- HTML-Template -->   
    <v-form-base id="custom-id" @update:custom-id= "update" />  
    #custom-id {...} 

Type - Classnames

Style all items of a specific type, then use type specific classnames. They start with type- appended by any type. You can use following types in your Schema-Object:

    #form-base .type-text { color: #44A }}           	  
    #form-base .type-email { font-weight:500; }  

Key - Classnames

Set Classname of deep key in your Data-Object, by converting .dot notation 'person.adress.city' into kebab case 'person-adress-city' prepending 'key-'

    <!-- 
	    myValue{ person:{ adress:{ city:'',... } ... } ... } 
      CSS Classname to access to key 'city'
    -->
    #form-base .key-person-adress-city { font-weight:500; }    
    

    <!-- 
      Access to myValue: { name:'' }
      CSS Classname to access key 'name' 	       
    -->
    #form-base .key-name { font-weight:500; }            
    
    <!-- 
      myValue: { controls: { slide: [25, 64]  } 
      Access First Entry in Array of Key Slide 
    -->
    #form-base .key-controls-slide-0 { font-weight:500; }  

Validate with Pseudoselectors

    #form-base .item input:valid { background-color: #afa; }
    #form-base .type-email input:invalid { background-color: #faa; }
    #form-base .key-name input:focus { background-color: #ffd; }   

CSS - Example

    <!-- JS -->
    myValue: {
        name: 'Base',
        password: '123456',
        email: '[email protected]',
        controls: {
          checkbox: true,
          switch: true,
          slider: 33,
          radioA: 'A',
          radioB: 'B'
        }
      }
     <!-- CSS  -->
    <style>
      #form-base { 
        border: 1px solid #cb2; 
        background-color: #ffe; 
        padding:2rem 
      }
      
      /* CSS Item --- set all items  */
      #form-base .item { 
        border-left: 1px dashed #29D; 
        border-top: 1px dashed #29D; 
        padding:1rem 
      }

      /* CSS Type --- set all items with type */
      #form-base .type-switch { border-bottom: 3px solid #E23}
      #form-base .type-checkbox { background-color: #fdd }

      /* CSS Keys --- select key in object 'myValue.controls.slider' */
      #form-base .key-controls-slider { background-color: #fec }
    </style>

Slots in Blue


Features

  • Vue-Component
  • integrates UI framework Vuetify 2.0 with responsive Layout and Support of Grid
  • Use Vuetify Control & Input types inclusive most of available API-Props
  • Define and use custom Components
  • Get full configurable Forms based on Schema Definition
  • Full control over Grid
  • Drag and Drop Integration
  • Edit plain or deep nested objects including Arrays, without the need to flatten your data
  • Get a full, reactive Result
  • Listen on 'Resize', 'Focus', 'Input', 'Blur', 'Click', 'Swipe', 'Intersect', 'Mouse' and 'Update' Events
  • Use Slots to pass Header and Footer into a Control or replace a Control by a Slot. Use Slots to individualize your Tooltip
  • Configurable CSS Style

Change

See change.log


Dependencies

vue >= 2.6 - current vuetify doesn't support vue 3.0

vuetify >= 2.0

lodash > 4.15

vue-the-mask


Similar Projects

vue-form-generator

vue-formular


License

vuetify-form-base is available under the MIT license.

vuetify-form-base's People

Contributors

brunosmm avatar dependabot[bot] avatar mcmimik avatar mrpaulharris avatar wotamann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vuetify-form-base's Issues

Unknown custom element errors

Tried copy pasting the example and I get console errors:


[Vuetify] [UPGRADE] 'v-content' is deprecated, use 'v-main' instead.

found in

---> <VMain>
       <App> at src/App.vue
         <Root>

Unknown custom element: <v-row> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^2.6.11",
    "vuetify": "^2.3.7",
    "vuetify-form-base": "^0.2.4"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.4.0",
    "@vue/cli-plugin-eslint": "~4.4.0",
    "@vue/cli-service": "~4.4.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "sass": "^1.19.0",
    "sass-loader": "^8.0.0",
    "vue-cli-plugin-vuetify": "~2.0.7",
    "vue-template-compiler": "^2.6.11",
    "vuetify-loader": "^1.3.0"
  },

main.js:

import Vue from 'vue'
import App from './App.vue'
import vuetify from './plugins/vuetify'

Vue.config.productionTip = false

new Vue({
  vuetify,
  render: h => h(App)
}).$mount('#app')

Vuetify does in fact work.

Installed using vue-cli 4.4.6 and vue add vuetify

Using a-la-carte.

v-autocomplete not works with custom search (for fetch from database, f.e.)

SOLUTION: add code like this after

          <!-- autocomplete -->
            <v-autocomplete
              v-else-if="obj.schema.type === 'autocomplete'"
              v-bind="bindSchema(obj)"                 
              :value="setValue(obj)"
              :obj="obj"
              **:search-input.sync="obj.schema.search"**
              @focus="onEvent($event, obj)"
              @blur="onEvent($event, obj)"
              @click:append="onEvent($event, obj, append)"
              @click:append-outer="onEvent($event, obj, appendOuter)"
              @click:clear="onEvent($event, obj, clear )"
              @click:prepend="onEvent($event, obj, prepend )"
              @click:prepend-inner="onEvent($event, obj, prependInner )"
              @input="onInput($event, obj)"
            />
          <!-- END autocomplete -->

Using:

in data

 schema: {
  date: { type: 'date', ext:'text', flex: 4, locale:'ru', label: 'Дата' },        
  name: { type: 'text', label: 'Имя', flex: 4 },
  owner: { type:'autocomplete', label:'Owner', 
    itemText:'login',
    itemValue:'id',
    items: [],
    loading: false,
    **search: '',**
    hideNoData: true
  }
},

life state

   mounted(){
     this.$watch('schema.owner.search', function ( val ) {
     val && val !== this.schema.owner.select && this.queryUsers(val)
   })
 },

in methods

async queryUsers( v ){
  try {
      const { data } = await this.$apollo.query( { 
          query: user.fetchByName,
          variables:{
            name: v+'%'
          }
      })
      this.schema.owner.items = data.users
  } catch ( err ) {
      this.schema.owner.items = []
      console.log({ err })
  }
},

It is working examle for my proect

Select & Combobox don't work

First, I love this component. I was just about to homebrew something of my own like it, then I thought, "I should check if anyone has already invented that wheel." I'm glad I did.

I do have a problem, though. When I set an element's type property to "select" or "combobox," I get an error saying "Unknown custom element: <v-select>" (or v-combobox).

My schema looks like this:

{
	initiativeBonus: {
		type: "number",
		label: "Initiative Bonus",
		col: 12
	},
	addWeapon: {
		type: "text",
		prependIcon: "mdi-plus-circle",
		ext: "hidden",
		flat: true,
		solo: true,
		col: 1,
	},
	weapons: {
		type: "array",
		col: 11,
		schema: {
			name: {
				type: "text",
				label: "Name",
			},
			type: {
				type: "select",
				label: "Type",
				items: [
					"Simple Melee",
					"Simple Ranged",
					"Martial Melee",
					"Martial Ranged",
				],
			},
			range: {
				type: "text",
				label: "Range",
			},
			damageType: {
				type: "combobox",
				label: "Damage Type",
				items: [
					"Acid",
					"Bludgeoning",
					"Cold",
					"Fire",
					"Force",
					"Lightning",
					"Necrotic",
					"Piercing",
					"Poison",
					"Psychic",
					"Radiant",
					"Slashing",
					"Thunder",
				],
			},
			bonuses: {
				type: "group",
				label: "Bonuses",
				col: 12,
				schema: {
					toHit: {
						type: "number",
						label: "To Hit",
					},
					toDamage: {
						type: "number",
						label: "To Damage",
					},
				},
			},
			damage: {
				type: "text",
				label: "Damage",
				hint: "1d8, 2d10, ...",
			},
			link: {
				type: "text",
				label: "Info Link",
			},
		},
	},
}

Hi Team

Will it support vuetify 1.5++

Thanks,
Sakthi

fromCtrl and toCtrl not changing the model

Hello,

I am trying to sync two fields, so the second field can use the value of the first one:


    email: {
      type: 'text',
      label: 'Email',
      rules: [rules.email],
    },
    username: {
      type: 'text',
      label: 'Username',
      readonly: true,
      toCtrl: ({ data }) => data && data.email,
      fromCtrl: ({ data }) => data && data.email,
    },
}

on the ui, the value is change whenever email field is modified, but when the form is submitted the username model value is empty.

Is there other way I can synchronize the fields or this is a bug?

using:
"vuetify": "2.3.4",
"vuetify-form-base": "^0.1.22",

thanks

Nested Data-Object

Hi,
i need help about how to add subheader to nested object.

So if i create object data like this:
mySchema: {
section_title: { type: 'text', label: 'Section title'},
section_subtitle: { type: 'text', label: 'Section subtitle'},
feature_1:{
title: { type: 'text', label: 'Title'},
subtitle: { type: 'text', label: 'Subtitle'},
} ,
feature_2:{
title: { type: 'text', label: 'Title'},
subtitle: { type: 'text', label: 'Subtitle'},
}
feature_3:{
title: { type: 'text', label: 'Title'},
subtitle: { type: 'text', label: 'Subtitle'},
}
}
How to separate it in groups so it goes:

Section title input
Section subtitle input


Subheader: Feature 1
Title input
Subtitle input


Subheader: Feature 2
Title input
Subtitle input


Subheader: Feature 3
Title input
Subtitle input

Because now inputs are one after another.

Populate model with an object

Is it possible to populate model field with an object value?
Im trying to do it like in example below - but it cannot be handled in flattenObjects method .

thanks!

model:

{
   "somefield": "{id:1,value:'Some value'}",

}

schema:
"somefield": { "type": "select", "returnObject": true itemText: "value", itemValue: "id", },

I request a piece of advice...

Hi there

For a while I have been working on a designer app using Vuetify and now want to adopt some part of it to vuetify-form-base. Below is the schema of what my app gets to build, this I later to create an UI at runtime as a mock. Im using this basically for code generation.

I want now to somehow provide a preview-screen of what the for will look like using a dialog.

Name - the database table field name
Title - should appear on the label of each component
Component - the type of component to render
R - row
C - column
OS - OX - offsets
SS - SX - size per device

designer

Most of the details here are linked to an underlying database table. For example, for each field, I provide it a title, the row location and column location. This also goes for the component type. As one can use different devices, I also indicate the sizes for the devices. What Id like to know is what is the best approach to bring a schema like this to vuetify-form-base? Do I create schemas per each row for vuetify-form-base? considering that some rows might have different sizes per device?

This is my output from my designer without using vuetify-form-base at the moment generated from the definitions above.

designer1

Thank you.

Error with empty model

"vue": "2.6.11",
"vuetify": "2.3.4",
"vuetify-form-base": "0.1.22",

ERROR vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in created hook: "No 'model' definition found. Use '<formbase :model="myData" />' "

Schema - { "start": { "type": "group", "label": "Start", "schema": { "to": { "type": "group", "label": "To", "test": { "type": "text", "label": "Test" } }, "from": { "type": "text", "label": "From" } } } }

Model - { "start": { "from": "some text" } }

In some cases model can be empty or not with all fields.

Thanks for your time.

Vuetify v2

Hello. I'm going to try your component. In examples i see vuetify v1.5. But what if i use vuetify v2 branch? How compatible are they with this component?

Month picker display issue

Hi, in my project I am trying to use the month picker in menu, but i didn't find the correct options in vuetify-form-base schema's. Please suggest a solution to fix my issue.

CDN Version

Good day, I am using vuetify via the cdn version and thus not using imports.

Is it possible for you to also provide a compiled version of your component to JavaScript please. If there is a way I can use it as is on the <script> tag that will also be fine you can advise.

Thank you again for this wonderful amazing piece of art.

Using groups

Hi.

First of all, thanks for your amazing component, it reminds me of Symfony's FormType.

Here i came after using your component and i was wondering something.

I'm using Vuex with Vuex-Orm and it works like a charm.
I have a Client model and schema like this :

Schema :

export const ClientSchema = {
    email: {
        type: 'text',
        label: 'Email',
        flex: 4,
        class: 'mx-2',
        outlined: true
    },
    siret: {
        type: 'text',
        label: 'Siret',
        flex: 4,
        class: 'mx-2',
        outlined: true
    },
    siteWeb: {
        type: 'text',
        label: 'Site web',
        flex: 4,
        class: 'mx-2',
        outlined: true
    },
    raisonSociale: {
        type: 'text',
        label: 'Raison sociale',
        flex: 4,
        class: 'mx-2',
        outlined: true
    },
    code: {
        type: 'text',
        label: 'Code',
        flex: 4,
        class: 'mx-2',
        outlined: true
    },
    telephoneMobile: {
        type: 'text',
        label: 'Téléphone Mobile',
        flex: 4,
        class: 'mx-2',
        outlined: true
    },
    telephoneFixe: {
        type: 'text',
        label: 'Téléphone Fixe',
        flex: 4,
        class: 'mx-2',
        outlined: true
    },
    codeNaf: {
        type: 'text',
        label: 'Code naf',
        flex: 4,
        class: 'mx-2',
        outlined: true
    },
    fax: {
        type: 'text',
        label: 'Fax',
        flex: 4,
        class: 'mx-2',
        outlined: true
    },
}

Model :

import {Model} from '@vuex-orm/core'

export class Client extends Model {
    static entity = 'Client'
    static fields() {
        return {
            id: this.string(null),
            email: this.string(''),
            siret: this.string(''),
            siteWeb: this.string(''),
            commentaire: this.string(''),
            raisonSociale: this.string(''),
            code: this.string(''),
            telephoneMobile: this.string(''),
            telephoneFixe: this.string(''),
            codeNaf: this.string(''),
            fax: this.string(''),
            actif: this.boolean('')
        }
    }
}

This is only the first and little part i'm implenting.
I would like to know if i can group attributes, like Group 1 : label => Infos within a v-card and another group Legal within another card.

It would be very great to use groups for large form.

Example : https://vue-generators.gitbook.io/vue-generators/groups

Regards.

SSR mode not works in NuxtJS (mode: 'universal')

Errors in SSR mode:

SyntaxError
Unexpected token '<'

in SPA - all works

I got message:

[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside

, or missing . Bailing hydration and performing full client-side render.

when using the form in ssr

        <v-form-base 
            :model="model" 
            :schema="schema" 
            @input="handleInput"
        />

data: () =>({
dialog: true,
item_idx: -1,
item: {
date: '',
name: 'My Name',
},
schema: {
date: { type: 'date', ext:'text', locale:'ru', label: 'Дата' },
name: { type: 'text', label: 'Имя' },
},
}),

Error somwere in:

flattenObjects()

because after i commented body of the function all start works on SSR, but incorrectly (no form),
after i uncommenter the fuction and nuxt updated page on client side ONLY form was shown
Then i update page in browser (reread from server) - error comes back

error messages

pages/test.js:1340:63
vFormBase.vue:905:
VueComponent.flattenObjects
vFormBase.vue:941:
VueComponent.flattenAndCombineToArray
vFormBase.vue:964:
VueComponent.rebuildArrays
vFormBase.vue:969:
VueComponent.created

How to detect arrow keys presses?

I have an custom number input, and I'm increasing or decreasing it's value based on user's click, but I want it to change with up and down keys too

Captura de Pantalla 2019-10-31 a la(s) 11 05 01

Template:

v-form-base(:value="values" :schema="schema" @update="update")

Schema:

value: {
  type: 'text',
  label: 'Value',
  flex: 3,
  appendIcon: 'add',
  prependInnerIcon: 'remove',
  outlined: true,
  dense: true
}

Update event:

update({ on, key, params }) {
  if (on == 'click' && key == 'value') {
    if (params.text == 'add') {
      this.values.value++
    }
    if (params.text == 'remove' && this.values.value > 0) {
      this.values.value--
    }
  }
}

Error using v-form-base in dialog

Hello,

First, thanks for sharing this lib, seems really impressive! 👍

I am trying to use it, creating a component with a dialog and the v-form-base inside, code below, but I am getting an error on the console. The form is using the schema and model from the readme file. I am using the version 0.2.6.

ERROR:
image

CODE:

<template>
    <v-dialog v-model="dialog" max-width="500px">
        <v-card>
            <v-form>
                <v-form-base
                    cols="12"
                    :model="myModel"
                    :schema="mySchema"
                    @input="handleInput"
                />
            </v-form>
        </v-card>
    </v-dialog>
</template>

<script>
import VFormBase from 'vuetify-form-base';
export default {
    name: 'NewProductDialog',
    components: { VFormBase },
    props: {
        dialog: { type: Boolean, default: false },
    },
    data() {
        return {
            myModel: {
                name: 'Jumo',
                password: '123456',
                email: '[email protected]',
                checkbox: true,
                select: 'Jobs',
            },
            mySchema: {
                name: { type: 'text', label: 'Name' },
                password: { type: 'password', label: 'Password' },
                email: { type: 'email', label: 'Email' },
                checkbox: { type: 'checkbox', label: 'Checkbox' },
                select: {
                    type: 'select',
                    label: 'Select',
                    items: ['Tesla', 'Jobs', 'Taleb'],
                },
            },
        };
    },
    methods: {
        handleInput(val) {
            console.log(val);
        },
    },
};
</script>

<style scoped></style>

Can anyone help with this problem?

Cheers

How does one bind the "items" to an attribute

Hi there

Instead of specifiying items for selects etc like items = ['A', 'B', 'C']

How do I achieve the same by assigning such to the state like :items="itemSource", where itemSource is stored on the Vue instance?

Thank you.

Change event not emit in group

If i create something like this

template

<v-form> <VFormBase :value="myValue" :schema="mySchema" @change="test('change')" @input="test('input')" /> </v-form>

script

` myValue: {
group1: {
name: 'John',
},
},

  mySchema: {
    group1: {
      type: 'card',
      title: 'Card Title',
      schema: {
        name: { type: 'text', label: 'Name label' },
      },
    },
  },

methods: {
test(e) {
console.log(e);
},
},
`

Change event not emitted for card type the same issue for array type.

How to create simple array of text values

This works
model: { values: [{}, {}, {}] }, schema: { name: { type: 'text', label: 'Name', }, values: { type: 'array', schema: { value: 'text' } } }

How to create array of text values instead of array of objects?
Next does not work:

model: { values: ['','',''] }, schema: { name: { type: 'text', label: 'Name', }, values: [ type: 'text', ] }

I need to create in example select2 field with tag style. Autocomlete + create not existing.

vue-the-mask dependencies is mssing

Hi,

You should add vue-the-mask dependencies in package.json as it keep saying "vue-the-mask is missing".

solve it using npm i vue-the-mask --save

unknown custom element error: v-checkbox, v-select

While trying to implement your simple form example (copy paste), I get the following error for checkbox and select types:

Unknown custom element: <v-select> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

Text works. I have not tried other control types.

Vue 3.3.0

What is the best way to re-mound a form based on some new data?

I'm trying to change the form schema dinamically, but I'm getting some troubles...

Here's some example:

<template>
    <div>
        <v-form>
            <v-select center :items="strategy_list" label="Strategy" v-model="strategy" **@input= "updateForm"**> </v-select>
            <v-form-base :value="values" :schema="schema" />          
        </v-form>
    </div>
</template>
...
    data() {
        return {
            values: {
                name: 'Jumo',
            },   
            schema: {
                name: { type: 'text', label: 'Name' },
                password: { type: 'password', label: 'Password' },
             }
        }
    },
methods: {
        updateForm() {
            console.log(this.strategy);
            **this.schema = {};
            this.values = {};**
            ...
            **// Updates the schema based on strategy's new data**

What am i doing wrong?

Tooltip Bug

Hi

To reproduce, add a text with a tooltip.
Add a date picker

Result: Number tooltip shown on date

Expected Result: Number tooltip to show closer to the parent control.

TooltipError

Storing Value and Schema Objects in a database.

Hello wotamann,

you have done a great job with vFormBase. I enjoy using it very much.

I am wondering if it is possible to store the value and schema objects in a database and load them dynamically.

Somewhat like that.

Value: {
}

Schema: {
} 

axios.get('/')
  .then(function (response) {
    this.Value = response.data.Value
    this.Schema = response.data.Schema
 }

}

model not updating form

for example using

<v-form-base :model="test" :schema="test"/>
...
<script>
...
<!-- at some point in the code -->
this.test = {item:"something"}
...
</script>

While the "test" variable has the value, but it won't show up in generated form. It shows an empty form. I got this bug after I updated vue and vuetify to the newest version. Looking at the code it seems setValue not updating correctly. Is there a solution for this?

Date picker for a v-text-field?

Looks very promising for basic schema forms (thank you), but I'm struggling to find an approach to integrate a date picker into a v-text-field. Have tried using both slots and a custom typeToComponent extension without luck. Any guidance or hints would be greatly appreciated. TIA

How to use the masks?

I try to follow as stated in the documentation, however, when I put in place to mask as in vuetifyjs does not run.

Vuetify: 2.0.0
Vue: 2.6.10
Lodash: 4.17.3

Using Vuetify native classes

Hi !

The project is awesome so first of all, congratulations.
I'm checking the docs but I couldn't find any related to use Vuetify element classes like "Solo", "Box" and the rest.

There's any way to use them?

Thank you !

Vuetify has no v-array component for data-arrays

Could you please clarify the documentation on data-arrays? Trying to use them, I get that the custom component v-array is not defined.
Are we supposed to create a custom component ourselves, and if so, could you provide a sample component?
Otherwise, which Vuetify component should we be using, list ie. change 'array' to 'list'? The array data might require manipulating to fit the component in this case.

Thanks

Populating the data from Serve

hi Team,

I want to populate the data from Server in to form base. I couldn't generate the JSON like your format. I able to hard code manually but from array i am not able generate as generic.

Thanks,
Sakthi

Rendering form from json file

How to add validation rules from .json file and dynamically change or add the custom color for fields in vuetify-form-base?

syntax error in description

Hello there, thank you for the great extension project, there additional character in the description in the template section, from beginning at 10 rows: >

Awesome

Wow, thanks a lot for this!

I will explore as I will start using this now!

The data received from back end doesn't load on form on front end

Hey, before all, i need thank you for this amazing package! But i have a problem with him.
I created a schema in back end to mount the front end's form, but when I change the value( this event is responsible for get data for back end) the form doesn't appear in the screen...
Can you help me please? Thanks!

Follow the schema that I set up:
DevTools - localhost8080

Follow the values of schema:
DevTools - localhost8080_2

And my application without form
Help Desk - Google Chrome_2

Tooltips with slots?

Hello, is there a possibility to integrate tooltips via slots? I have not been able to do it yet and would be very grateful for a hint. My current solution includes a modification of VFormBase.vue, which I'm not really happy about. It would be great to control the tooltips via the schema. TIA

Cascading selection

How to make this dynamic so i dont need log function to push items to another array?

Thanks

How to add tooltip for appended or prepended icons in vuetify-form-base ?

<template>
  <v-container fluid>
    <h4>Textfields and Fileselector with Mask and Tooltips</h4>

    <v-form>    
      <v-form-base
        :value="myValue"
        :schema="mySchema"
        @input="log"
      />

    </v-form>

    <infoline
      :value="myValue"
      :schema="mySchema"
      :path="$options._componentTag"
    />
  </v-container>
</template>

<script>
import VFormBase from '@/components/vFormBase'
import Infoline from '@/components/infoline'
import log from '@/lib'

const mask = '####-####-####-####'

const accept = 'image/*'

export default {
  name: 'Textfields',
  components: { VFormBase, Infoline },
  data () {
    return {
      myValue: {
        name: 'Base',
        creditcard: '12345678',
        password: 'abcdefgh',
        file: [] // array of File objects
      },      
      mySchema: {        
        name: 'text',         
        password: { 
          type: 'password', 
          clearable: true, 
          flex: 12 
        },
        creditcard: { 
          type: 'text', 
          label: 'Creditcard', 
          prependInnerIcon: 'credit_card', 
          hint: mask, 
          mask, 
          tooltip: 'Creditcard', 
          flex: 12 
        },
        file: { 
          type: 'file', 
          label: 'Files', 
          accept, 
          multiple: true, 
          tooltip: { color: 'green', label: 'File Selection', top: true }, 
          flex: 12 
        }
      }
    }
  },
  methods: {
    log
  }
}
</script>

From the above code tooltip is applied for entire textfield by using tooltip: 'Creditcard' but i want tooltip only for icon. Now tooltip is applied on hover of entire text field but it should display only on hover of icon.

Reference :1. https://github.com/wotamann/vuetify-form-base 2. https://wotamann.github.io/

Input event not fired

I want to listen to the input event so i can dynamically add items on autocomplete.
The selection will be updated as the user type in the value on the autocomple.

However, the onInput method never get called.

<v-form-base :schema="schema" :value="value" @input="onInput">

Row gutters in grouped controls

I have a schema with this setup:

    stats: {
      type: "group",
      label: "Stats",
      col: 6,
      class: "bordered overline pa-2",
      schema: {
        str: {
          type: "number",
          label: "STR",
          col: 2,
        },
        dex: {
          type: "number",
          label: "DEX",
          col: 2,
        },
        con: {
          type: "number",
          label: "CON",
          col: 2,
        },
        int: {
          type: "number",
          label: "INT",
          col: 2,
        },
        wis: {
          type: "number",
          label: "WIS",
          col: 2,
        },
        cha: {
          type: "number",
          label: "CHA",
          col: 2,
        },
      },
    },

It works fine, but I'd like to put some gutters between the fields. I did that globally on the rest of the form with: :row="{ justify: 'center', align: 'center', noGutters: false }" and it works like a charm, but that global setting doesn't carry through into the grouped items.

Am I overlooking something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.