Git Product home page Git Product logo

vue-use-form's Introduction

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

vue-use-form's People

Contributors

logaretm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vue-use-form's Issues

Looks great!

Looking forward to using it and give some constructive feedback. What do you think is missing to be considered production-ready, albeit in beta form? Any backstage thought on this library? Cheers!

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.