0.2.6 • Published 1 year ago

vue-form-lite v0.2.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

This library is for vue3

Example init script

import formLite from "vue-form-lite";

// example interface
interface IPost {
  title: string | null;
  description: string | null;
}

// ref from vue
const state = ref<IPost>({
  title: null,
  description: null,
});

// init form
const { handleSubmit } = formLite({
  state,
});

// handle for getting validated values
const onSubmit = handleSubmit(async (val: IPost) => {
  // values in form
  console.log(val);
});

Form template

<form class="todo-mutation" @submit="onSubmit" method="post">
    <input v-model="state.title" />
    <input v-model="state.description" />
    <button class="todo-mutation__btn">Send</button>
</form>

Errors validate

const state = ref<IPost>({
  title: null,
  description: null,
});

const {
  errors,
  setError,
  setErrors,
  clearError,
  clearErrors,
} = formLite({
  state,
});

// Set error for one field
setError("title", "This field has an error");
// for multiple fields or all
setErrors({
  description: "Incorrect description",
});

// clear error for one field
clearError("title");
// clear all errors
clearErrors();

Add validate rules

import formLite from "vue-form-lite";
// rules library
import { required, minLength } from "@vue-form-lite/rules";

// custom rule
const checkSuper = (val: any) => (val === "super" ? true : "It's not super");

const { handleSubmit, errors, $valid } = formLite({
  state,
  rules: {
    title: {
      required,
      // custom rule
      checkSuper,
      // Some functions require arguments to be specified
      minLength: minLength(4),
    },
  },
});
0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago