1.3.6 • Published 2 years ago

@moirei/vuetify-dynamic-form v1.3.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

vuetify-dynamic-form (Vue 2)

Defining and creating form components and their validation can be tedious and repetitive. This package allows you to dynamically define form inputs with configurable options.


:green_heart: Features

  • Dynamically create form input fields
  • Two-way binded form data. Useful when using forms in update context and the implementing component may update/provide the initial data
  • vee-validate v3 validation
  • Slots to customise field components
  • Flexible configuration for validation, auto-grouping, component props, etc.

Installation

npm i --save @moirei/vuetify-dynamic-form
# or yarn add @moirei/vuetify-dynamic-form

Usage

import Vue from 'vue'
import VDynamicForm from '@moirei/vuetify-dynamic-form'
import CustomComponent from './CustomComponent'

Vue.use(VDynamicForm)

// Or with options
Vue.use(VDynamicForm, {
  interactionMode: "aggressive",
})

new Vue({}).$mount('#app')

// then inside your vue components
export default Vue.extend({
  data: () => ({
    form: {},
    inputs: {
      first_name: {
        name: "First Name",
        rules: "required|max:24",
        type: "text",
        line: 1,
        props: {
          filled: true,
        },
      },
      last_name: {
        name: "Last Name",
        rules: "max:24",
        component: "v-text-field", // Use a compnent name
        line: 1,
        props: {
          filled: true,
        },
      },
      address: {
        name: "Address",
        component: CustomComponent, // Use a component
        props: {
          filled: true,
        },
      },
    },
  })
})

<template>
  <v-dynamic-form v-model="form" :input-fields="inputs" />
</template>

API

Props

NameRequired?DefaultTypeDescription
valueyesstringThe v-model input prop
hide-namenofalsebooleanWhether to hide input name displayed above the component field
loadingnofalsebooleanIndicates the form or its data is in loading state. All inputs are disabled if true.
readonlynofalsebooleanSets all inputs to readonly
disablednofalsebooleanDisables all inputs
disable-object-rewritenofalsebooleanDo not clone and emit new object for form data. When enabled, field input property is updated on the form data and the input event is not fired.
hide-actionsnofalsebooleanHides the SUBMIT and CLEAR actions
defaultsno{}objectDefault form values to prepopulate the inputs with
interaction-modenostringSet the default interaction mode for all inputs
input-fieldsyesobjectThe dynamic form fields
nested-fieldsnofalsebooleanAllow nested fields. When true, field names like "address.line1" will be saved as property line1 in object address within the form data. To use array as nested key, use the key field option.
validnobooleanForm validation state. Use with valid.sync.

Field options

FieldDefaultTypeDescription
colobjectProps to bind to v-col with multiple fields in one line
componentstring|Component
hideName/hide-namefalsebooleanHide the input display name
keyField keystringstring[]Specify the field key in the form data
propsobjectInput component props
rulesstring|arrayVee-validate rules
typeUses <input > tag if empty and component is also empty.stringVuetify input types. Valid values: text, select, checkbox, slider, range-slider, switch, textarea and radio
modeaggressivestringVee-validate mode
nameField keystringThe input display name
vidField keystringInput field validation ID

Plugin options

FieldDefaultTypeDescription
interactionMode"aggressive"stringConfigure global default interaction mode

Events

NameDescription
inputThe v-model input event
submitEmitted when the form is validated and submitted.
update:validThe valid.sync prop event

Slots

NameDescriptionProps
field:validation:{field}Use to override an input at the validation-provider level.{ field }
field:{field}Use to override an input at the component level.{ ...field, invalid, errors }
actionsUse to override the default SUBMIT and CLEAR actions{ submit, clear, invalid }

Functions

NameDescription
submitValidates and emits submit event if valid
clearResets the form data and validation states
resetReset the validation observer
validateValidates all inputs and child forms

Classes

NameDescription
v-dynamic-formThe components class
v-dynamic-form--inputsThe class group for all inputs
v-dynamic-form--actionsThe class group for the default actions

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Changelog

Please see CHANGELOG.

Credits

License

MIT

1.3.6

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago