Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

formvuelar

Package Overview
Dependencies
Maintainers
1
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formvuelar

Vue form components with server side validation in mind.

  • 0.1.8
  • npm
  • Socket score

Version published
Weekly downloads
17
increased by54.55%
Maintainers
1
Weekly downloads
 
Created
Source

Formvuelar

Vue form components with server side validation in mind

Formvuelar basic form

FormVuelar is a set of predefined vue form components which are designed to automatically display errors coming back from your backend. It works out of the box with the error message bag that is returned by Laravel when submitting an ajax form.

Examples

Give it a try!

Features

- Works out of the box with Laravel
- Axios integration
- File upload support including process indicator
- Dropzone with image preview (inspired by FilePont)
- Display validation error messages from error response

Getting Started

npm install formvuelar --save

Available Components

The following components are shipped with FormVuelar:

NameDescriptionImport Name
<fvl-form />Form wrapper elementimport { FvlForm } from 'formvuelar'
<fvl-input />Input fieldimport { FvlInput } from 'formvuelar'
<fvl-textarea />Text area fieldimport { FvlTextarea } from 'formvuelar'
<fvl-radio />Radio input fieldimport { FvlRadio } from 'formvuelar'
<fvl-checkbox />Check box input fieldimport { FvlCheckbox } from 'formvuelar'
<fvl-select />Select input fieldimport { FvlSelect } from 'formvuelar'
<fvl-file />File input fieldimport { FvlFile } from 'formvuelar'
<fvl-multi-file />Multi file input fieldimport { FvlMultiFile } from 'formvuelar'
<fvl-dropzone />Dropzone fieldimport { FvlDropzone } from 'formvuelar'
<fvl-submit />Submit buttonimport { FvlSubmit } from 'formvuelar'

Components Props & Events

NameProp/EventTypeDefaultPossible valuesNotes
fvl-form:methodString'post'get|post|put|patch|delete
:dataObject{}{}
:urlStringnull
:multipartBooleanfalsetrue|false
@successFunctionaxios response
@errorFunctionaxios error response
@upload-progressFunction0-100
fvl-input:value.syncData''form.name
:idStringnull
:nameString''
:labelStringnull
:typeString'text'
:placeholderStringnull
:autocompleteStringnull
:field-classStringnull
:minNumbernull
:maxNumbernull
:sizeNumbernull
:stepNumbernull
:requiredBooleanfalsetrue|false
:readonlyBooleanfalsetrue|false
:disabledBooleanfalsetrue|false
:patternStringnullregex
fvl-textarea:value.syncData''form.about
:idStringnull
:nameString''
:labelStringnull
:placeholderStringnull
:autocompleteStringnull
:field-classStringnull
:colsNumbernull
:maxlengthNumbernull
:rowsNumbernull
:wrapBooleannullhard|soft
:requiredBooleanfalsetrue|false
:readonlyBooleanfalsetrue|false
:disabledBooleanfalsetrue|false
:patternStringnullregex
fvl-select:selected.syncDatanullform.favoriteColor
:optionsObject{}{'key': 'value', ...}
:idStringnull
:nameString''
:labelStringnull
:allow-emptyBooleanfalsetrue|false
:placeholderStringnull
:autocompleteStringnull
:requiredBooleanfalsetrue|false
:readonlyBooleanfalsetrue|false
:disabledBooleanfalsetrue|false
fvl-radio:checked.syncDatanullform.newsletter
:optionsObject{}{'key': 'value', ...}
:idStringnull
:nameString''
:labelStringnull
:requiredBooleanfalsetrue|false
:readonlyBooleanfalsetrue|false
:disabledBooleanfalsetrue|false
fvl-checkbox:checked.syncDatanullform.terms
:idStringnull
:nameString''
:labelStringnull
:requiredBooleanfalsetrue|false
:readonlyBooleanfalsetrue|false
:disabledBooleanfalsetrue|false
fvl-file:file.syncDatanullform.avatar
:idStringnull
:nameString''
:labelStringnull
:requiredBooleanfalsetrue|false
:readonlyBooleanfalsetrue|false
:disabledBooleanfalsetrue|false
fvl-multi-file:files.syncDatanullform.gallery
:idStringnull
:nameString''
:labelStringnull
:requiredBooleanfalsetrue|false
:readonlyBooleanfalsetrue|false
:disabledBooleanfalsetrue|false
fvl-dropzone:files.syncDatanullform.media
:idStringnull
:nameString''
:labelStringnull
:requiredBooleanfalsetrue|false
:readonlyBooleanfalsetrue|false
:disabledBooleanfalsetrue|false
fvl-submit:loaderBooleanfalsetrue|false
:disabledBooleanfalsetrue|false

Basic Form Template

Create a form and sent it via post request to your server.

<!-- form wrapper -->
<fvl-form method="post" :data="form" url="/create">

    <!-- Text input component -->
    <fvl-input
        :value.sync="form.fullname"
        label="Full Name"
        name="fullname"
    />

    <!-- Textarea component -->
    <fvl-textarea
        :value.sync="form.bio"
        label="Bio"
        name="bio"
    />

    <!-- Radio component with options -->
    <fvl-radio
        :checked.sync="form.pet"
        :options="{'cat': 'Cat', 'dog': 'Dog'}"
        label="Favorite pet"
        name="pet"
    />

    <!-- Submit button -->
    <fvl-submit>Validate</fvl-submit>

</fvl-form>

The form object you pass into the form component above would look like this:

import { FvlForm, FvlInput, FvlTextarea, FvlRadio, FvlSubmit } from 'formvuelar'
...
    components: {
        FvlForm,
        FvlInput,
        FvlTextarea,
        FvlRadio,
        FvlSubmit,
    },
    data() {
        return {
            form: {
                fullname: '',
                bio: '',
                pet: ''
            },
        ...

Error Response

The response from your Backend should contain a Json error object and have a status of 422 in order to show the error messages below the input fields. This response format is default for Laravel and will work out of the box.

{
  "message": "The given data was invalid.",
  "errors": {
    "field-1": [
      "Error 1",
      "Error 2"
    ],
    "field-2": [
      "Error 1",
      "Error 2"
    ]
  }
}

Client side validation

You can still use the default HTML5 validation rules for all input fields like 'accept' and 'required' for file inputs:

    <fvl-file
        label="Avatar"
        name="avatar"
        :file.sync="form.avatar"
        accept="image/*"
        required
    />

Styling

The styling is totally up to you. All components have their own classes so you have full control over the look and feel of every component.

Every component is wrapped with a div and the corresponding class .fvl-{type}-wrapper. Labels have a class name of .fvl-{type}-label. The field itself has a class name of .fvl-{type}

Example classes of the text input component (using Tailwind)

.fvl-input-wrapper {
    @apply p-2;
}
.fvl-input-label {
    @apply block uppercase tracking-wide text-grey-darker text-xs font-bold mb-2;
}
.fvl-input {
    @apply appearance-none block w-full bg-grey-lighter text-grey-darkest border border-grey-lighter rounded py-3 px-4 leading-tight;
}

I'm using Tailwind CSS for the examples. Feel free to use the predefined css component classes for your own projects.

TODO

- Advanced select component with search and remote source option
- Tags component

Keywords

FAQs

Package last updated on 10 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc