Giter Site home page Giter Site logo

dlodeprojuicer / ionic-vue-form Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 3.6 MB

Render fully customizable dynamic form with form-field conditional logic.

Home Page: https://codesandbox.io/s/mystifying-bash-4c6iu?file=/src/components/HelloWorld.vue

Vue 98.50% JavaScript 1.50%

ionic-vue-form's Introduction

Ionic Vue Form

Render fully customizable dynamic form with form-field conditional logic.

Install

npm install ionic-vue-form

// Register globally (optional)
import { IonicVueForm } from "ionic-vue-form"

Vue.component("IonicVueForm",IonicVueForm)


// Register locally (optional)
<script>
  import { IonicVueForm } from 'ionic-vue-form'

  export default {
    components: {
      IonicVueForm
    }
  }
<script>

Basic usage

<template>
  <div>
    <IonicVueForm :formFields="form" btnText="Submit" @submit="submit" />
  </div>
</template>

<script>
  import { IonicVueForm } from 'ionic-vue-form'

  export default {
    components: {
      IonicVueForm
    },
    data () {
      return {
        form: [
          {
            key: "email",
            label: "Email"
          },
          {
            key: "password",
            label: "Password
          }
        ]
      }
    },
    methods: {
      submit(data) {
        // Submit logic
        // data - Form input(s)
      }
    }
  }
</script>

Note

In your project's main.js import and use vee-validate

import VeeValidate from 'vee-validate'

Vue.use(VeeValidate)

Auto-fill example

data prop takes the data object, binds each key-value pair to the relavent form field

<template>
  <div>
    <IonicVueForm :formFields="form" :data="formData" btnText="Submit" @submit="submit" />
  </div>
</template>

<script>
  import { IonicVueForm } from 'ionic-vue-form'

  export default {
    components: { IonicVueForm },
    data () {
      return {
        form: [
          {
            key: "first_name",
            label: "First name"
          },
          {
            key: "last_name",
            label: "Last name
          }
        ],
        formData: {
          first_name: "John",
          last_name: "Doe"
        }
      }
    },
    methods: {
      submit(data) {
        // Submit logic
        // data - Form input(s)
      }
    }
  }
</script>

Props

Name Type Required Default Description
formFields Array true - List of fields to render
data Object false - Form datta (if you need to auto-fill the form)
btnText String false Continue Submit button text
wrapperClass String false - Form wrapper class

Events

Event Description Parameters
submit Submit form -
fileUpload Useful when you want to handle file processing separately -

Field Properties

  • key required | String Must be unique, the key will be used in formData.
  • type optional | String Input type, defaults to text.
  • label optional | String Input field's label
  • validation optional | String Field validation rules, Ionic vue form uses VeeValidate
  • class optional | String Input CSS class
  • rows optional | Integer rows attribute for textarea input
  • rows optional | Integer cols attribute for textarea input
  • options required | Array List of option values for select dropdown
  • condition optional | Object Show number field if email value is [email protected]
{
  key: "email",
  label: "Email",
},
{
  key: "number",
  type: "number",
  label: "Number",
  condition: {
    key: "email",
    value: "[email protected]"
  }
}
  • component is required if type is component. If the component requires props you can use props property which takes an object

This is useful when you want to use a 3rd party component in your form. In the example below, I want to use vue-multiselect in my form.

<script>
import multiselect from "vue-multiselect";

export default {
  data() {
    form: [
      {
        key: "category",
        label: "Select Category",
        type: "component",
        component: multiselect,
        props: {
          options: [],
          multiple: true,
          closeOnSelect: false,
          clearOnSelect: false,
          hideSelected: true,
          preserveSearch: true,
          trackBy: "category_label",
          label: "category_label"
        }
      }
    ]
  }
}

Demo

Sandbox Demo

Ionic Vue Form Screenshot

ionic-vue-form's People

Contributors

dlodeprojuicer avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ksarpotdar

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.