2.0.9 • Published 3 years ago

@me_slack/vue2easyform v2.0.9

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

Vue2EasyForm

Vue2EasyForm is a Vue2 component which makes working with forms very easy indeed.

Simply pass the Form Prop into the component and it will Emit Events as they happen.

On submit it will validate the inputs and return @error or if successful a @submit {key:value} object.

  • Image (small video/gif)

Install

npm install --save @me_slack/vue2easyform@latest vuesax@^3 @boxicons@^2
import Vue from 'vue'
import Vuesax from 'vuesax'

import 'vuesax/dist/vuesax.css'
<link rel="stylesheet" href="https://unpkg.com/boxicons@2.0.9/css/boxicons.min.css">

Required Dependencies

Optional Dependencies

  • We recommend Boxicons and use it as fallbacks in places.

Usage

import VueEasyForm from "@me_slack/vue2easyform"

data: () => ({
    contact_form: {
        name: 'contact_form',
        fields: [{
            key: 'email',
            value: '',
            input: {
                type: 'email',
                placeholder: 'Email',
            },
            required: true
        }, {
            key: 'submit',
            submit: {
                label: 'Send Email'
            }
        }]
    },
})
<VueEasyForm :form="conact_form" @submit="sendEmail" @updated_email="updateEmail"></VueEasyForm>

Props

The only prop you need is form this is the JSON object which builds out the form fields, buttons, etc.

This is made up as follows:

PropertyTypeRequiredDescriptionDiv #id
namestringtrueUsed to help differentiate between multiple forms on the same pagevef_form_${name}
fieldsarraytrueAn array holding a number of field objects. Options include: input, textarea, dropdown, checkbox, module, button, submit, markdown, submitvef_fields
displaystringWrap the form with a display css element
debugbooleanWill print emits and other helpful debugging into the console, default false

Fields

fields:[
    {
        key: 'email',
        value: 'me@me.com'
    }
]

This is the key you will get back in any events. For example:

{
    email: 'me@me.com'
}

You can pass the following values:

PropertyTypeRequiredDescriptionDiv #id
keystringThe key for the key:pair returned on update/submission
<mixed>objecttrueWe currently support the following fields: input, textarea, dropdown, checkbox, button, module, markdown, submit , sectionvef_field_${key}
value<mixed>trueThe property which holds the user input.
loadingbooleanShow a loading spinner in place of the field. Helpful if you are populating from an APIvef_loading_${key}
descriptionstringShow the user a message below the field.vef_description
autocompletestringThe string to use for the autocomplete see WHATWG HTML standard
requiredbooleanIf this a required field
disabledbooleanIf the field should be disabled
hiddenbooleanHides the field from view (default false)
responsiveobjectAllows you to set the width of the column {lg: 6, sm: 12, xs: 12}
classstringAllows you to pass in classes dynamically
stylestringAllows you to pass in styles dynamically
successbooleanIf the field has been successfully validated
success_messagestringThe success messagevef_success_message
errorbooleanIf the field has failed validation
error_messagestringThe error messagevef_error_message
validationobjectPass additional validation params, see validation
transformobjectPass additional transformation params, see transform

Input

A field with the Div #id vef_input_${key}

PropertyTypeRequiredDescription
typestringtrueCurrently supports text email url
labelstringThe label of the input
placeholderstring
label-placeholderstring
iobjectSee Icon
i_successobjectSee Icon, defaults to bx bx-check
i_errorobjectSee Icon, defaults to bx bx-error

Example:

{
    email: {
        type: 'email',
        label: 'Email Address',
        value: 'me@me.com',
        placeholder: 'jon.doe@email.com',
    }
}

Textarea

A field with the Div #id vef_textarea_${key}

PropertyTypeRequiredDescription
labelstringThe label of the textarea.
counterNumberDetermines the maximum number of characters.
widthstringSet the width of the textarea
heightstringSet the width of the textarea

Example:

{
    message: {
        label: 'Message',
        counter: 150
    }
}

Dropdown

A field with the Div #id vef_dropdown_${key}

PropertyTypeRequiredDescription
labelstringThe label of the dropdown.
optionsarraytrueThe dropdown options passed as an array.
multiplebooleanDetermines whether the selection is of multiple selection.
autocompletebooleanEnables the use of autocomplete in the select.
iobjectElement icon See Icon

Example:

{
   label: "Do you want a truth or dare?",
   options: [{value: 'TRUTH', name: "Truth"}, {value: 'DARE', name: "Dare"}]
}

Checkbox

A field with the Div #id vef_checkbox_${key}

PropertyTypeRequiredDescription
labelstringIf you wish to add a label to the checkbox, Div #id vef_checkbox_label_${key}
colorstringColor options for checkBox.
iobjectSee Icon defaults to bx-check

Button

An input field with the Div #id vef_input_${key}

PropertyTypeRequiredDescription
labelstringThe text for the button
iobjectSee Icon

Module

Modules are pre-built form options which can reused with the Div #id vef_module_${key}, support types are:

timezone_dropdown, country_dropdown

An input field

PropertyTypeRequiredDescription
typestringtrueThe type of module to render

Pass the following properities depending on the type:

timezone_dropdown

PropertyTypeRequiredDescription
autocompletebooleanEnables the use of autocomplete in the select.
iobjectElement icon See Icon
localestring(5)Locale (e.g. en-GB)
labelstringThe label of the dropdown.

country_dropdown

PropertyTypeRequiredDescription
countrystring (ISO2)The country you wish to set as the default, if not passed we will attempt to lookup from browser settings.
autocompletebooleanEnables the use of autocomplete in the select.
iobjectElement icon See Icon
localestring(5)Locale (e.g. en-GB)
  • language dropdown (-mode -small (just symbols) - medium (just names) - large (names and symbols/shotcodes)) - options (array specify which ones to show otherwise all)
  • countires (-mode -small (just flags) - medium (just names) - large (names and flags/names)) - options (array specify which ones to show otherwise all)
  • address lookup - Will need to look for external modules
  • google maps - show on a map the location passed (will require google api keys to be passed)
  • light/dark switcher
  • Key/Pair list with ADD / REMOVE Options

Example:

{
    type: 'timezone_dropdown'
}

Submit

The forms submit button with Div #id vef_submit and vef_submit_button

PropertyTypeRequiredDescription
submitobject{label: 'Submit', i: null} See Icon

Example:

{
    submit: {
        label: "Submit"
    }
}

Section

You can split up your form with sections, passing the following options. #id vef_section_${key} class vef_section

PropertyTypeRequiredDescriptionIDClass
headerstringAdd a header to your sectionvef_section_${key}_headervef_section_header
textstringText for your sectionvef_section_${key}_textvef_section_text
hr_abovebooleanIf you wish to show a HR above the headervef_section_hr_above
hr_belowbooleanIf you wish to show a HR below the textvef_section_hr_below

Example:

{
    hr_above: true,
    header: "Section Title",
    text: "Section Text",
}

Shared

The following are reused elements

Validation

We are using ValidatorJS for validation.

PropertyTypeDescription
minnumberValidate that the value is at least a given size.
maxnumberValidate that the value is no greater than a given size.
inarrayValidate that the value is in array, e.g. ['truth', 'dare']
  • Add more validation options

Transform

Some fields allow you to transform content as it is entered, see below:

PropertyTypeDescription
uppercasebooleanIf passed we will transform input textarea to uppercase
lowercasebooleanIf passed we will transform input textarea to lowercase
  • Add more transform options

Icons

PropertyTypeDescription
iconstringThe icon you wish to use, e.g. bxs-heart
packstringThe icon-pack you have installed e.g. bx
afterstringPuts your icon after the element input button submit
classstringAllows you to pass in classes dynamically
stylestringAllows you to pass in styles dynamically

Events

The following events will be emitted to allow maximum flexibility to your application:

@submit

Once the submit button is pressed (if you have one), it will validate the form and return a json object with a {field: value} pair:

{
    email: 'users@email.address'
    message: 'The users message here'
}

@updated_{{field}}

  • Watch a single field for changes, you will get the value object emitted when it changes and passes validation.

@updated

  • Watch the entire form for changes, you will get the same object of results as @submit each time the form is updated, however this will not have been validated.

@clicked

If a user clicks on a button element, this event will fire with the name of your field as the value. This will also fire on submit

@error

Each time a field fails a validation check an @error event will fire, you can choose to consume it if you wish. You will receive a {field: message} object for failing fields.

Note: Validation checks happen both when field values change and on submit, you might receive multiple errors on a single form submission.

Examples

You can see some prebuild examples here:

  • Basic

  • Share more advanced examples

Shell Script

  • Create a runner.sh script which will allow users to build the form json by entering commands for even easier form setup.
2.0.7

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.1.3

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.9

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

0.1.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.5

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago