All Projects → blocka → vue-simpleform

blocka / vue-simpleform

Licence: MIT license
Form library for vue. Inspired by Formik for react.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to vue-simpleform

insect
🛠 Highly customisable, minimalistic input x select field for React.
Stars: ✭ 33 (-17.5%)
Mutual labels:  forms
streaming-form-data
Streaming parser for multipart/form-data written in Cython
Stars: ✭ 112 (+180%)
Mutual labels:  forms
final-form-arrays
Array Mutators for 🏁 Final Form
Stars: ✭ 64 (+60%)
Mutual labels:  forms
ember-validated-form-buffer
A validated form buffer that wraps Ember Data models for use in forms.
Stars: ✭ 46 (+15%)
Mutual labels:  forms
edulabs
No description or website provided.
Stars: ✭ 15 (-62.5%)
Mutual labels:  forms
ember-validity-modifier
Ember Octane addon to add custom validity (form validation) to form fields
Stars: ✭ 28 (-30%)
Mutual labels:  forms
LC-switch
Superlight vanilla javascript plugin improving forms look and functionality
Stars: ✭ 31 (-22.5%)
Mutual labels:  forms
MagicForm
The easiest way to make complex forms with validations.
Stars: ✭ 31 (-22.5%)
Mutual labels:  forms
react-forms-processor
A forms processor for React
Stars: ✭ 63 (+57.5%)
Mutual labels:  forms
forms
A library to build declarative, composable, reactive user interfaces with WebSharper.
Stars: ✭ 12 (-70%)
Mutual labels:  forms
RapidFormBundle
Create Symfony forms at record speed using PHP 8 attributes!
Stars: ✭ 33 (-17.5%)
Mutual labels:  forms
platform
A collection of minimalistic, easy-to-use and fully customizable Angular components, directives and services
Stars: ✭ 17 (-57.5%)
Mutual labels:  forms
mui-form-fields
Material UI + Final Form Forms and Components
Stars: ✭ 15 (-62.5%)
Mutual labels:  forms
form-saver
A simple script that lets users save and reuse form data.
Stars: ✭ 67 (+67.5%)
Mutual labels:  forms
SuluCommunityBundle
Community features like Login, Registration, Password forget/reset for your sulu application.
Stars: ✭ 20 (-50%)
Mutual labels:  forms
ng-xform
esss.github.io/ng-xform/home
Stars: ✭ 18 (-55%)
Mutual labels:  forms
Formidable
The PHP pragmatic forms library
Stars: ✭ 116 (+190%)
Mutual labels:  forms
django-jsonfield-backport
Backport of the cross-DB JSONField model and form fields from Django 3.1.
Stars: ✭ 36 (-10%)
Mutual labels:  forms
RDForm
Create and edit RDF data in a HTML form
Stars: ✭ 16 (-60%)
Mutual labels:  forms
talos
Elixir parameter validation library. Simple and extensible
Stars: ✭ 23 (-42.5%)
Mutual labels:  forms

vue-simpleform

A form library for vue, inspired by Formik for react

Is it really simple?

I think it is, but really I couldn't think of a better name

Basic Usage

<template>
<SimpleForm :value="initialValues" :validate="validate" @submit="handleSubmit">
    <template scope="{values, errors, touched, input, blur, setValue, setTouched, handleSubmit, submitted, submitting}">
    <form>
        <input type="email" v-on="{input, blur}" name="email" :value="values.email" />
        <span class="error" v-if="touched('email') && errors('email')">{{errors('email')}}</span>
        
        <button @click.prevent="handleSubmit">Submit</button>
    </form>
    </template>
</SimpleForm>
</template>
<script>
    import SimpleForm from 'vue-simpleform'
    
    export default {
        data () {
            return {
                initialValues: {
                    email: null
                }
            }
        },
        methods: {
            handleSubmit ({ values, errors, setSubmitting, setSubmitted }) {
                // if form is valid, errors will be undefined
            },
            validate (values) {
                return {
                    email: 'Email is invalid'
                }
            }
        },
        components: { SimpleForm }
    }
</script>

The main component takes two props:

  1. value. This is used to set the initial form state, which will be a deep copy of what is passed in.
  2. validate. This is a function which is called to validate the form. This happens when any of the fields are updated, or the form is submitted. It can return a promise to do asynchronous validation as of 1.0.0 it only works synchronously

And $emits a submit event when the form is submitted. The callback for the submit event takes an object with following keys:

  1. values
  2. errors
  3. setSubmitting
  4. setSubmitted

If the form is valid, errors will be undefined

The scoped slot is passed the following props:

  1. values. All the form values, but "flattened".
  2. errors. A function taking a name of a field, and returning it's error message (if invalid.
  3. touched. A function taking a name of a field, and returning if the field was touched
  4. input. Input and blur are functions ready to be passed in as event handlers. They are only useful on a real form field (eg., and element. The element needs a name attribute as well
  5. blur
  6. setValue. Manually set a field value. Useful for integrating a custom component
  7. setTouched. Ditto, but for setting touched
  8. handleSubmit. A callback that will initiate the submittion process
  9. submitted
  10. submitting

Other components

There are two other components which are useful for encapsulating common patterns, or removing boilerplate. They are available as named exports.

  1. <SimpleFormFieldSet>. This is used to make a set of fields which are prefixed. It can be used also to set up an array of fields
<template v-for="(item, i) of items">
  <SimpleFormFieldSet :name="`items[${i}]`" :value="item">

It can be passed a single component, or a scoped slot. The same props passed in from SimpleForm will be passed in (as props to the component, or as props of the scoped slot), but will all be namespaced.

  1. <Field> This component removes some of the boilerplate in hooking up inputs
<Field type="email" name="email" errorClass="error" />

Will render an <input type="email" for the field email. errorClass is an optional prop. The default value is error

It can also take an element or a custom component

<Field name="favoriteColor">
   <select>
      <option value="red">Red</option>
      <option value="yellow">Yellow</option>
      <option value="green">Green</option>
    </select>
</Field>
<Field name="customComponentValue">
  <CustomComponent />
</Field>

The custom component will have value and class (with the erroClass) injected as a props, and input and blur as listeners. So the custom component has to $emit input with the new value, and blur.

  1. <Error>
<Error name="email" class="error-label" tag="span">

Displays an error if the given field is touched and has an error to show. By defaul will use a div, but the tag prop can be used to use a different element.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].