0.0.36 • Published 3 months ago

vue3-schema-forms v0.0.36

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Vue3 Json Schema Form powered by Vuetify 🚀

Create dynamic and user-friendly forms effortlessly with the Vue3 and Vuetify. This library is designed to simplify form creation by leveraging the JSON Schema format.

Inspired by https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/

Documentation

The documentation and some of the testing was based on the Storybook application 👉 live

Check the changelog here 👉 @latest

Sample app with schema forms configuration 👉 here

Requirements

To relieve the library of dependencies as peerDependencies library takes:

  • js@3.4.3
  • jstify@3.4.9
  • axios@1.6.2 - in order to maintain the configuration from the host (e.g. token interceptor)
  • dayjs@1.11.10 - management and formatting of dates including time zones,
  • pinia@2.1.7 - managing the status of each form, reference values
  • js-i18n@9.6.4 - handling translations in the library
  • jsdraggable@4.1.0 - support for drag&drop interaction
npm i vue@3.4.14 vuetify@3.5.1 axios@1.6.5 dayjs@1.11.10 pinia@2.1.7 vue-i18n@9 vuedraggable@next

Installation

You can install vue3-schema-forms using npm:

npm install vue3-schema-forms

Usage

import { createVueSchemaForms } from 'vue3-schema-forms';

const schemaForms = createVueSchemaForms({});

createApp(App)
  .use(schemaForms)
  .mount('#app');

After importing the plugin, we can invoke the form-generating component and pass the appropriate props.

<template>
  <vue-schema-forms
    v-model='model'
    :schema='schema'
    :options='formOptions'
    :default-form-actions='true'
    :validation-behaviour="'messages'"
  >
  </vue-schema-forms>
</template>

<script>
  const formOptions = ref({});
  const model = ref({});
  const schema = ref({
    type: 'object',
    properties: {
      field1: {
        label: 'Field 1',
        layout: {
          component: 'text-field',
        },
      },
    },
  });
</script>

Props description

NameDefaultTypeDescription
model-objectjson object in which the values collected by the form will be stored
schema-SchemaJSON object conforming to the defined Schema interface, is responsible for the appearance, layout and type of fields generated by the form component
options-objectJSON object in which the user can define options common to multiple form fields
defaultFormActionsfalsebooleanflag, which is responsible for the visibility of the default form buttons in the #formActions slot
validationBehaviour"scroll"ValidationBehaviourA flag that defines the validation behavior after a failed attempt to validate the form. Available options "scroll" / "messages"

Options

In options, there are priorities in setting props for form fields:

  1. Defaults (!)
  2. FieldProps (!!)
  3. InputType Props (!!!)
  4. Specific props defined in layout (!!!!)

Example: If when defining a layout you specify props as they are in the default they will be overwritten

The following table shows the default values for each field

NameDefaultTypeDescription
digitsAfterDecimal2numberNumber of decimal places in the representation of numbers
fieldProps-objectOption to set props for each type of field
textFieldProps{'hide-details': 'auto',}objectOption to set props for text fields
textAreaProps{"rows": 3, "hide-details": "auto", "auto-grow": true}objectOption to set props for text-area fields
radioButtonProps{"density": "compact", "hide-details": "auto"}objectOption to set props for radio fields
buttonProps-objectOption to set props for button (duplicated section)
checkboxProps{"density": "compact", "hide-details": "auto", "multiple": true }objectOption to set props for checkbox fields
selectProps{"hide-details": "auto"}objectOption to set props for autocomplete/select fields

Component slots

NameDescription
formActionsThe slot contains predefined default actions for the form: validation, reset validation and reset form. The user is free to override this slot and write his own buttons using exposed functions from the component. Just give "ref" and enjoy a ready-made validation function that takes 3 options: no parameter / scroll / messages example

Integrated fields

NameDefault settingsComponentDescriptionLink
v-phone-input{ 'country-icon-mode': 'svg', 'countryLabel': t('countryLabel'), 'guess-country': true, 'include-countries': 'pl', 'gb', 'ru', 'de', 'us', 'es', 'fr', 'it'}phoneInternational phone field for Vuetify 3 and Vue 3.source

Plugin options

NameDefaultTypeDescription
formUpdateLoggerfalsebooleanenabling this option allows the console to preview the form model update event
customComponents-ComponentsThis option allows you to install your custom form fields. You need to specify the name and the component. The integration is on your side using the composables provided.
// example of adding options
const customs = {
  'user-input': UserInput,
};

const vueSchemaForms = createVueSchemaForms({
  customComponents: customs,
  formUpdateLogger: true
});

Tests

  1. cd to the project directory
  2. Install development dependencies: npm install
  3. Run the tests: npm test
  4. Run the storybook: npm run storybook
  5. Run storybook tests: npm run test-storybook

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

ToDo List

  • Ability to add validation functions in schema
  • Ability to mark "not-saveable" field in schema/model
  • Email input
  • Markdown input
  • File input
  • Table input
  • Rsql filter on dictionary
  • Signal for form is ready (for autosave but after initial model changes)
  • Create datetime field
  • Use resolveDepsComposable for deps on fields
  • Create editable sections
  • Change to use Engine props (decomposition)
0.0.36

3 months ago

0.0.34

3 months ago

0.0.35

3 months ago

0.0.33

3 months ago

0.0.30

4 months ago

0.0.31

4 months ago

0.0.32

4 months ago

0.0.29

4 months ago

0.0.27

4 months ago

0.0.28

4 months ago

0.0.26

4 months ago

0.0.24

4 months ago

0.0.25

4 months ago

0.0.23

5 months ago

0.0.22

5 months ago

0.0.21

5 months ago

0.0.20

5 months ago

0.0.19

5 months ago

0.0.18

5 months ago

0.0.17

6 months ago

0.0.16

6 months ago

0.0.15

6 months ago

0.0.14

6 months ago

0.0.13

6 months ago

0.0.12

6 months ago

0.0.11

6 months ago

0.0.10

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago