vue-schema-form
Vue form generator based on JSON schema
Installation
Quick Install
npm install --save git+http://60f15f52df5cc973766c47c26ab179c7c00b034b:adwidianjaya@git64.inimedia.co.id/adwidianjaya/vue-schema-form.git
Custom Install (Token Required)
npm install --save git+http://{gogs-token}:username@git64.inimedia.co.id/adwidianjaya/vue-schema-form.git
Available Fields
Setup
Import Component to your Vue Instance
;const app =el: '#app'components:'vue-schema-form': VueSchemaForm{returndata: ...schema: ...actions: ...options: ...};
Component Usage
<!-- vue-schema-form dependencies --><!-- for specific field dependencies, we recommend you to check out the /static/lib folder -->
Actions Buttons
There are three standard actions wrapped by buttons: submit, reset, and cancel.
- Submit action performs standard form submission action. The handler acts as callbacks and form data is provided. However, form validation may be written inside the handler functions.
- Reset action performs form reset, which means that all field will be filled with its default value (if possible).
- Cancel action performs form cancel. However, there is no special function embedded in cancel action. Instead, you may do other things, like close container modal.
actions:submit:name: 'submit' label: 'Submit' icon: 'fa fa-check' class: 'btn btn-primary'{console;}reset:name: 'reset' label: 'Reset' icon: 'fa fa-check' class: 'btn btn-sm btn-info'{vm$refsSchemaForm;}cancel:name: 'cancel' label: 'Cancel' icon: 'fa fa-remove' class: 'btn btn-sm btn-warning'{// close container modal, or do other things}
Guides
Text
data:name: 'Steve Job'schema:name:type: 'text'label: 'Name'placeholder: 'Your full name'help: 'Please type your full name'{console;}
Number
data:height: 170schema:height:type: 'number'label: 'Height'min: 0 //optionalmax: 0 //optionalstep: 001 //optional
data:email: 170schema:email:type: 'email'label: 'Email'
Currency
data:price: 100000schema:price:type: 'currency'label: 'Price'default: 0 //optionalmin: 0 //optionalmax: 1000000 //optional
Note: currency field supports only Indonesian Rupiah (Rp.) at the moment.
Phone Number
data:phone: 100000schema:phone:type: 'phone-number'label: 'Phone Number'delimiter: '-' //optional
Select
Select field may return two kind of value: optionValue, and Object.
Return optionValue:
data:gender: 2schema:gender:type: 'select'label: 'Gender'options:id: 1 label: 'Male'id: 2 label: 'Female'optionValue: 'id' // optional, default is 'id'optionLabel: 'label' // optional, default is 'label'
Return object:
data:gender: id: 1 label: 'Male'schema:gender:type: 'select'label: 'Gender'options:id: 1 label: 'Male'id: 2 label: 'Female'trackby: 'id'optionLabel: 'label' // optional, default is 'label'
Custom label:
data:gender: 2schema:gender:type: 'select'label: 'Gender'options:id: 1 label: 'Male'id: 2 label: 'Female'{return optionlabel + ' - ' + optionid;}
Select2
Dependencies: select2 (Get it here: http://select2.github.io)
Include select2 both js and css files:
Schema definition (similiar with common select field):
data:gender: 2schema:gender:type: 'select2'label: 'Gender'options:id: 1 label: 'Male'id: 2 label: 'Female'{return optionlabel + ' - ' + optionid;}
Select2 may return object as common select field do.
Auto Complete
Dependencies: jquery autocomplete (Get it here: https://www.devbridge.com/sourcery/components/jquery-autocomplete)
Include jquery autocomplete js files:
Schema definition:
data:country: 'Indonesia'schema:country:type: 'autocomplete'label: 'Country'options: 'Indonesia' 'Japan'
Date Time Picker
Dependencies: bootstrap-datetimepicker, developed by Malot (Get it here: http://www.malot.fr/bootstrap-datetimepicker)
Include both js and css files:
Schema definition:
data:birthday:schema:birthday:type: 'datetimepicker'label: 'Birth Day'mode: 'datepicker' // optional, default is 'datepicker'
Datetimepicker component provides three modes: datepicker, datetimepicker, and timepicker.
File Upload
Dependencies: fine-uploader (Get it here: http://fineuploader.com)
Include both js and css files:
Write qq-template which is required by fine-uploader. There are three available template types provided by fine-uploader. If you aren't satisfied and need more UIs, please refer to http://docs.fineuploader.com/branch/master/features/styling.html for more styling options.
<!-- gallery style template provided by fine-uploader as default -->
Schema definition:
data:files:id: 1filename: 'avatar_c80a99bd5fd4_128.png'uuid: '226a8e3a-2f52-4322-a2d5-a7be28cf50ec'filetype: 'image/png'schema:files:type: 'file-upload'label: 'Upload file'withDelete: trueendpoint: 'http://localhost/fine_uploader'itemLimit: 1 // optional, default is unlimitedhelp: 'This is help block' //optional
File upload field requires server endpoint which receive data as POST and DELETE request. For the details please refers to http://docs.fineuploader.com/branch/master/endpoint_handlers/traditional.html. However, vue-schema-form already comes with Laravel endpoint example, please check LaravelController.php. Laravel endpoint highly utilize migration and model to realize database table uploaded_files which track all uploaded file, so you can add relation to other object at the back end.
Complete Laravel package (https://github.com/inimedia/foundation) can be installed by running:
composer require inimedia/foundation
TODO
- add built in validator
- add two column support as option
- checkbox and radio
- list field and field button
Build and Debugging Setup
# install dependenciesnpm install# serve with hot reload at localhost:8080npm run dev# build for production with minificationnpm run build# run unit testsnpm run unit# run e2e testsnpm run e2e# run all testsnpm test
For detailed explanation on how things work, checkout the guide and docs for vue-loader.