All Projects → logaretm → vue-use-form

logaretm / vue-use-form

Licence: MIT license
✅ A Vue.js composition API function to validate forms

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to vue-use-form

Usetheform
React library for composing declarative forms, manage their state, handling their validation and much more.
Stars: ✭ 40 (-58.76%)
Mutual labels:  forms, form, form-validation
ATGValidator
iOS validation framework with form validation support
Stars: ✭ 51 (-47.42%)
Mutual labels:  form, form-validation, validation-library
Jafar
🌟!(Just another form application renderer)
Stars: ✭ 107 (+10.31%)
Mutual labels:  forms, form, form-validation
ember-validity-modifier
Ember Octane addon to add custom validity (form validation) to form fields
Stars: ✭ 28 (-71.13%)
Mutual labels:  forms, form, form-validation
Final Form
🏁 Framework agnostic, high performance, subscription-based form state management
Stars: ✭ 2,787 (+2773.2%)
Mutual labels:  forms, form, form-validation
React Final Form
🏁 High performance subscription-based form state management for React
Stars: ✭ 6,781 (+6890.72%)
Mutual labels:  forms, form, form-validation
React Controlled Form
Flexible, Modular & Controlled Forms for React and Redux
Stars: ✭ 121 (+24.74%)
Mutual labels:  forms, form, form-validation
React Hook Form
📋 React Hooks for form state management and validation (Web + React Native)
Stars: ✭ 24,831 (+25498.97%)
Mutual labels:  forms, form, form-validation
Form bloc
🔥 Dart and Flutter Package 🔥 Easy Form State Management using BLoC pattern 🔥 Wizard/stepper forms, asynchronous validation, dynamic and conditional fields, submission progress, serialization and more! 🔥
Stars: ✭ 239 (+146.39%)
Mutual labels:  forms, form, form-validation
Redux Form
A Higher Order Component using react-redux to keep form state in a Redux store
Stars: ✭ 12,597 (+12886.6%)
Mutual labels:  forms, form, form-validation
grav-plugin-form
Grav Form Plugin
Stars: ✭ 48 (-50.52%)
Mutual labels:  forms, form, form-validation
react-cool-form
😎 📋 React hooks for forms state and validation, less code more performant.
Stars: ✭ 246 (+153.61%)
Mutual labels:  forms, form, form-validation
Form For
ReactJS forms made easy
Stars: ✭ 118 (+21.65%)
Mutual labels:  forms, form, form-validation
Composable Form
Build type-safe composable forms in Elm
Stars: ✭ 179 (+84.54%)
Mutual labels:  forms, form, form-validation
FrontendForms
A module for ProcessWire CMS to create and validate forms on the frontend easily using the Valitron library.
Stars: ✭ 0 (-100%)
Mutual labels:  forms, form, form-validation
form-data-json
A zero dependency, cross browser library to easily get or set/manipulate form input values as/from a json object.
Stars: ✭ 37 (-61.86%)
Mutual labels:  forms, form, form-validation
final-form-arrays
Array Mutators for 🏁 Final Form
Stars: ✭ 64 (-34.02%)
Mutual labels:  forms, form
svelte-multistep-form
Svelte MultiStep Form like, this component is still in beta stage
Stars: ✭ 29 (-70.1%)
Mutual labels:  forms, form
react-formulation
Simple React form validation
Stars: ✭ 14 (-85.57%)
Mutual labels:  forms, form
FilterInputJs
Tiny and Powerful Library for limit an entry (text box,input) as number,string or more...
Stars: ✭ 37 (-61.86%)
Mutual labels:  form-validation, validation-library

vue-use-form

Deprecated.

This project will be continued in the future releases of vee-validate starting with vee-validate@4 which will come with Vue.js 3 support.


This is a Vue composition API function that allows you to do form validation, powered by vee-validate.

Install

Not production ready yet.

yarn add vue-use-form

# OR

npm i vue-use-form

Usage

In your component file:

import { ref } from '@vue/composition-api';
import { useForm, useField } from 'vue-use-form';

export default {
  setup() {
    const fname = ref('');
    const { form, submit } = useForm({
      onSubmit () {
        console.log('Submitting!', {
          fname: fname.value
        });
      }
    });

    const { errors } = useField('firstName', {
      rules: 'required',
      value: fname,
      form
    });

    return { fname, errors, submit };
  }
};

In your Template:

<form @submit.prevent="submit">
  <input v-model="fname">
  <span>{{ errors[0] }}</span>
  <button>Submit</button>
</form>

API

useForm(object)

The useForm function accepts options to configure the form.

const { form, submit } = useForm({
  onSubmit () {
    // this will only run when the form is valid.
    // send to server!
  }
});

It returns an object containing two properties:

  • form: A form controller object, which can be used with useField to associate fields in the same form.
  • submit: A safe form submit handler to bind to your submission handler, it will validate all the fields before it runs the given onSubmit handler.

useField(string, string | object)

The useField function accepts a string which is the input name, and options to configure the field:

const field = useField('firstName', {
  rules: 'required', // vee-validate style rules, can be a Ref<string>.
  value: fname, // the initial field value, optional.
  form // a form controller object returned from "useForm", used to group fields. optional.
});

It returns the following members:

Prop Type Description
flags ValidationFlags Object containing vee-validate flags for that field.
errors string[] list of validation errors
validate () => ValidationResult Triggers validation for the field.
reset () => void Resets validation state for the field.
onInput () => void Updates some flags when the user inputs, you should bind it to the element.
onBlur () => void Updates some flags when the user focuses the field, you should bind it to the element.
value Ref<string> A default ref in-case you didn't pass the initial value

Credits

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].