Form generation scheme from a JSON schema
Tags: javascript, vue, json, schema
Published: 2019-10-16 03:33:03

![banner](https://user-gold-cdn.xitu.io/2019/3/3/16943deeb66bcd43?w=700&h=692&f=png&s=139107)

Sarah: "There are a lot of forms for new business system to be developed. Is there a solution that make me to do this task efficiently and happily?"

Oh, I think, configuration development concept should be more suitable, and the community also has some open source projects of this concept.

Sarah: "What is the configuration development concept?"

On, just simply define a JSON configuration data to develop the form.

Sarah: "Great, I am going to search now."

After a while...

Sarah: "There are a lot of them, but which one do I choose?"

Well, let's talk about the selection of configuration concept form development implementation.

---

**1. Document**

This is essential, no documentation, who dares to use it?

**2. Live Playground**
 
It's best to have a super-intuitive, super-image, super-convenient way to show most or all of the features, which might be like this:

![image](https://user-gold-cdn.xitu.io/2019/3/3/16943abe4f959bac?w=971&h=524&f=gif&s=349703)

**3. Out Of The Box**

It is best to come with a set of commonly used form controls and validation rules to meet most common scenarios, so you don't have to expand too much on your own.

For example, the following components are often used:

![image](https://user-gold-cdn.xitu.io/2019/3/3/169433c41da39d40?w=218&h=298&f=gif&s=56474)

For example, the following verification rules are often used:

![image](https://user-gold-cdn.xitu.io/2019/3/3/169433c41f7d5cf9?w=695&h=359&f=png&s=93622)

**4. Expansion Ability**

No more components and validation rules can meet all the requirements. So must be **friendly (simple and convenient)** support developers to customize their own form components and validation rules

**5. Support for complex data structures**

A form data structure, in addition to a simple object type with only one level attribute (such as `{name: 'daniel', age: 18}`), many actual scenes might look like this:

```json
{
  "name": {
    "firstName": "daniel",
    "lastname": "xiao"
  }
}
```

It might be like this:

```json
{
  "name": "daniel",
  "hobbies": [
    {
      "id": 1,
      "name": "Coding"
    },
    {
      "id": 2,
      "name": "Singing"
    }
  ]
}
```

Summary: must support for array type, object nested object, object nested array, array items are normal type or object type or array type

**6. Form Control Interaction**

The form controls are not independent, they interact with each other

Here are some representative scenes：

- "Agree to continue" type
![image](https://user-gold-cdn.xitu.io/2019/3/3/16943b249d93c1c7?w=540&h=275&f=gif&s=26353)

![image](https://user-gold-cdn.xitu.io/2019/3/3/16943b71f5ce0923?w=769&h=286&f=gif&s=43103)

- "City Selector" type
![image](https://user-gold-cdn.xitu.io/2019/3/3/16943b8f8292baf9?w=456&h=173&f=gif&s=78443)

- "Required filling in when more than 18 years old" type
![image](https://user-gold-cdn.xitu.io/2019/3/3/16943cca160441eb?w=430&h=218&f=gif&s=25523)

- "Date Comparison" type
![image](https://user-gold-cdn.xitu.io/2019/3/3/16943d27e9c97c7a?w=441&h=208&f=gif&s=56300)

- "Full name autofill" type
![image](https://user-gold-cdn.xitu.io/2019/3/3/169433c455b2b873?w=432&h=189&f=gif&s=12875)

I feel that there are already quite a lot of them. I will not list them one by one.

So, sarah, if the candidate open source project can meet the above mentioned conditions, then it can be used.

Sarah: "Oh, do you have a recommendation?"

Of course. I recommend **ncform**

---

ncform, a nice form development way that generates form UIs and their interactions with just configuration.

Comes with standard components and validation rules, out of the box.

Have powerful control interaction and extension capabilities, do what you want.

Visit the official Github for more information: [https://github.com/ncform/ncform](https://github.com/ncform/ncform)

tags: vue, form, generator, json-schema