All Projects → vue-formily → formily

vue-formily / formily

Licence: MIT license
Simple, lightweight, and flexible schema-based form for Vue.js

Programming Languages

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

Projects that are alternatives of or similar to formily

Epage
一款基于schema的可视化页面配置工具
Stars: ✭ 194 (+743.48%)
Mutual labels:  schema, form
vue-example
Vue.js example application (server-side rendering, router, vuex store, form validation, i18n & l10n)
Stars: ✭ 62 (+169.57%)
Mutual labels:  schema, form
fform
Flexibile and extendable form builder with constructor
Stars: ✭ 26 (+13.04%)
Mutual labels:  schema, form
Schema Plugin Flow
A highly extensible JavaScript library, abbreviated as Sifo. 一个高扩展性、可二开的插件式前端开发框架
Stars: ✭ 288 (+1152.17%)
Mutual labels:  schema, form
Vue Rawmodel
RawModel.js plugin for Vue.js v2. Form validation has never been easier!
Stars: ✭ 79 (+243.48%)
Mutual labels:  schema, form
Native
Generate a form using JSON Schema and Vue.js
Stars: ✭ 382 (+1560.87%)
Mutual labels:  schema, form
Vue Form Generator
📋 A schema-based form generator component for Vue.js
Stars: ✭ 2,853 (+12304.35%)
Mutual labels:  schema, form
Fielder
A field-first form library for React and React Native
Stars: ✭ 160 (+595.65%)
Mutual labels:  schema, form
Vue Form Json Schema
Create forms using JSON schema. Bring your components!
Stars: ✭ 253 (+1000%)
Mutual labels:  schema, form
mapper
Map tarantool tuples to php objects.
Stars: ✭ 68 (+195.65%)
Mutual labels:  schema
DroidValidatorLight
Android form validation library
Stars: ✭ 32 (+39.13%)
Mutual labels:  form
schema2ldif
Schema 2 ldif : tool to convert .schema to .ldif files and mange them live into an openldap server
Stars: ✭ 14 (-39.13%)
Mutual labels:  schema
SuluFormBundle
Form Bundle for handling Dynamic and Symfony Forms in https://sulu.io
Stars: ✭ 51 (+121.74%)
Mutual labels:  form
react-drip-form
☕ HoC based React forms state manager, Support for validation and normalization.
Stars: ✭ 66 (+186.96%)
Mutual labels:  form
react-useForm
World's simplest React hook to manage form state
Stars: ✭ 30 (+30.43%)
Mutual labels:  form
contact-officials
Form definitions powering Resistbot's electronic deliveries to elected officials in the United States.
Stars: ✭ 29 (+26.09%)
Mutual labels:  form
hasura-sdk
Hasura Schema & Metadata Typescript SDK
Stars: ✭ 21 (-8.7%)
Mutual labels:  schema
really-rich-results
RRR makes structured data for WordPress really rich, and really easy.
Stars: ✭ 21 (-8.7%)
Mutual labels:  schema
WMZForm
一个功能强大的表单组件,可自定义(A powerful form component that can be customized)
Stars: ✭ 38 (+65.22%)
Mutual labels:  form
antd-react-form-builder
Example
Stars: ✭ 74 (+221.74%)
Mutual labels:  form


Simple, lightweight, and flexible schema-based form for Vue.js

Features

🧽  Flexible: Easily to handle from basic to nested forms, group of forms...

⚙️  Dynamically: Generate form components dynamically.

📝  Schema: Build faster form by schema.

🐜  Lightweight: Small built size. Gzip: ~5 KB

  Validation: Validate form elements with built-in Rules that covers most needs in most web applications

🧩  Plugins: Extend functionally by third-party plugins or your own plugins.

🌵  Extensibility: Easily to make your own custom form element by extending the core elements.

Links

Installation

CDN

You can use vue-formily with a script tag and a CDN, import the library like this:

<!-- vue 3.x -->
<script src="https://unpkg.com/@vue-formily/formily@next"></script>
<!-- vue 2.x -->
<script src="https://unpkg.com/@vue-formily/formily@latest"></script>

This will inject a VueFormily global object, which you will use to access the various components, funtions exposed by vue-formily.

If you are using native ES Modules, there is also an ES Modules compatible build:

<script type="module">
  // vue 3.x
  import Vue from 'https://unpkg.com/@vue-formily/formily@next/dist/formily.esm.js'
  // vue 2.x
  import Vue from 'https://unpkg.com/@vue-formily/formily@latest/dist/formily.esm.js'
</script>

NPM

# install with yarn
# vue 3.x
yarn add @vue-formily/formily@next
# vue 2.x
yarn add @vue-formily/formily

# install with npm
# vue 3.x
npm install @vue-formily/formily@next --save
# vue 2.x
npm install @vue-formily/formily --save

Set Up

Vue 3.x

import { createApp } from 'vue'
import { createFormily } from '@vue-formily/formily';

const formily = createFormily();

const app = createApp(App)

app.use(formily, {
  // By default, vue-formily will execute the 
  // validation silently when changing element's value.
  // To disable it, just set the `silent` to `false`.
  // When disabled, the element has to be validated manually 
  // by calling the `element.validate()` method.
  silent?: boolean;
  // The default rules want to apply to the form.
  // With rules that have the `cascade = true`,
  // then thay can apply to all the child elements.
  rules: [];
  // The alias of the object contains all the form references
  // that will be injected to Vue instance
  alias: 'forms';
});

Vue 2.x

import Vue from 'vue';
import { createFormily } from '@vue-formily/formily';

const formily = createFormily();

Vue.use(formily, {
  // By default, vue-formily will execute the 
  // validation silently when changing element's value.
  // To disable it, just set the `silent` to `false`.
  // When disabled, the element has to be validated manually 
  // by calling the `element.validate()` method.
  silent?: boolean;
  // The default rules want to apply to the form.
  // With rules that have the `cascade = true`,
  // then thay can apply to all the child elements.
  rules: [];
  // The alias of the object contains all the form references
  // that will be injected to Vue instance
  alias: 'forms';
});

Vue Version Support

The main v2 version supports Vue 3.x only, for previous versions of Vue, check the following the table

Vue Version vue-formily version
2.x 1.x
3.x 2.x

Basic Usage

Let's start with a simple login form:

Defining Form Schema

vue-formily need a form schema to work with, so let's define one:

import { defineSchema } from '@vue-formily';
import { required, email } from "@vue-formily/rules";

const loginForm = defineSchema({
    formId: 'login',
    formType: 'group',
    fields: [
      {
        formId: 'email',
        formType: 'field',
        type: 'string',
        format: '{raw}',
        value: '',
        rules: [
          {
            ...required,
            message: 'Please enter email address.'
          },
          {
            ...email,
            message: 'Please enter valid email address.'
          }
        ],
        props: {
          label: 'email',
          inputType: 'email'
        }
      },
      {
        formId: 'password',
        formType: 'field',
        type: 'string',
        rules: [
          {
            ...required,
            message: 'Please enter password.'
          }
        ],
        value: '',
        props: {
          label: 'password',
          inputType: 'password'
        }
      }
    ]
  });

Create New Form

Then we call $formily.add to create new form element and injects it to Vue instance's forms object.

<template>
  <form class="login">
    <div v-for="(field, i) in forms.login.fields" :key="i" class="field">
      <label :for="field.formId">{{ field.label }}</label>
      <input v-model="field.raw" :type="field.props.inputType" :name="field.name" :id="field.formId" />
    </div>
  </form>
</template>

<script>
//  Vue 2.x
export default {
  created() {
    // Create new form element and injects it to `forms` object.
    this.$formily.add(loginForm);
  }
}

// Vue 3.x
import { useFormily } from '@vue-formily';

export default {
  setup() {
    const formily = useFormily();
    // Create newå form element and injects it to `forms` object.
    formily.add(loginForm);
  }
}
</script>

Here is the live demo.

Contributing

You are welcome to contribute to this project, but before you do, please make sure you read the Contributing Guide.

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