GithubHelp home page GithubHelp logo

ncform / ncform Goto Github PK

View Code? Open in Web Editor NEW
1.2K 37.0 149.0 10.71 MB

🍻 ncform, a very nice configuration generation way to develop forms ( vue, json-schema, form, generator )

License: MIT License

JavaScript 83.77% Vue 16.08% CSS 0.12% SCSS 0.03%
json-schema vue form form-schema generator playground schema-generation

ncform's Introduction

ncform

CircleCI vue 2.x license MIT Cypress.io tests Gitter lerna

中文版

ncform banner

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.

If you are hesitant, you can read this article: How to choose

Playground


Playground

Experience the charm of ncform on the Playground to deepen your understanding of ncform

Playground shows the examples of ncform most of the use of the scene ( I believe the examples are the best document ), it is recommended to carefully browse the examples, the configuration of the examples can be used directly in the actual development

Quick Start

In node.js

1.install

npm i @ncform/ncform @ncform/ncform-common --save
npm i @ncform/ncform-theme-elementui element-ui axios --save 

2.import

import Vue from 'vue';
import vueNcform from '@ncform/ncform';

import Element from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import ncformStdComps from '@ncform/ncform-theme-elementui';
import axios from 'axios';

Vue.use(Element);
Vue.use(vueNcform, { extComponents: ncformStdComps, /*lang: 'zh-cn'*/ });
window.$http = Vue.prototype.$http = axios;

3.usage

# demo.vue

<template>
  <div>
    <ncform :form-schema="formSchema" form-name="your-form-name" v-model="formSchema.value" @submit="submit()"></ncform>
    <el-button @click="submit()">Submit</el-button>
  </div>
</template>
<script>
export default {
  data () {
    return {
      formSchema: {
        type: 'object',
        properties: {
          name: {
            type: 'string'
          }
        }
      }
    }
  },
  methods: {
    submit () {
      this.$ncformValidate('your-form-name').then(data => {
        if (data.result) {
          console.log(this.$data.formSchema.value)
          // do what you like to do
        }
      })
    }
  }
}
</script>

You can refer to the ncform-demo project

In browser

<html>

<head>
  <link rel="stylesheet" href="https://unpkg.com/[email protected]/lib/theme-chalk/index.css">
</head>

<body>
  <div id="demo">
    <ncform :form-schema="formSchema" form-name="your-form-name" v-model="formSchema.value" @submit="submit()"></ncform>
    <el-button @click="submit()">Submit</el-button>
  </div>

  <script type="text/javascript" src="https://unpkg.com/vue/dist/vue.min.js"></script>
  <script type="text/javascript" src="https://unpkg.com/axios/dist/axios.min.js"></script>

  <script type="text/javascript" src="https://unpkg.com/@ncform/ncform-common/dist/ncformCommon.min.js"></script>
  <script type="text/javascript" src="https://unpkg.com/@ncform/ncform/dist/vueNcform.min.js"></script>

  <script type="text/javascript" src="https://unpkg.com/element-ui/lib/index.js"></script>
  <script type="text/javascript" src="https://unpkg.com/@ncform/ncform-theme-elementui/dist/ncformStdComps.min.js"></script>

  <script type="text/javascript">
    Vue.use(vueNcform, { extComponents: ncformStdComps, /*lang: 'zh-cn'*/ });

    // Bootstrap the app
    new Vue({
      el: '#demo',
      data: {
        formSchema: {
          type: 'object',
          properties: {
            name: {
              type: 'string'
            }
          }
        }
      },
      methods: {
        submit() {
          this.$ncformValidate('your-form-name').then(data => {
            if (data.result) {
              // do what you like to do
            }
          });
        }
      }
    });
  </script>
</body>

</html>

Features

  • Configuration generation: A JSON data structure completely describes the UI of a form and its interaction behavior, and the development of the form is completed.

  • Flexible interaction: Form controls flexibly interact with each other with powerful dx expressions

  • Standard components: ncform defines a standard set of form component configuration specifications that can meet more than 90% of your form development needs without extensions.

  • Rich verification: ncform comes with more than ten commonly used verification rules to meet more than 90% of your form validation requirements

  • Extended friendliness: Form components and validation rules can be flexible extended and provide tools to simplify extension work

Documents

Solve Pain Points

Most of the features in the management system are not the query list, that is, the form.
The development of the form is a boring, nutrient-free, high-consumption repetitive physical activity that takes time and effort.
The interaction between the form controls and the validation rules of the form items are very easy to produce bugs.
So, in order to improve the efficiency of form development, reduce bugs, improve form development specifications and robustness, and most importantly, improve the development happiness of developers, the project is born

Repeat the wheel?

A similarly well-known scheme in the community ( listed in the reference projects ) has one or more of the following problems:

  1. Basically designed in accordance with json-schema, but it is not appropriate to use json-schmea to describe a form.

  2. For the interaction between form items, complex verification logic, there is no good solution

  3. Can't complete all the UI and interaction behavior of the form with just one configuration ( meaning the configuration can be stored )

  4. The underlying components provided by default are not rich enough to cover the form components commonly used in actual development.

  5. Long time no maintenance, code writing style is too old and is difficult to expand

  6. Component extension problem: There is no friendly extension solution for the current hot component implementations like Vue and React.

In order to solve the above problems, embarked on the road of making wheels. . .

Why not use the standard json-schema?

Because json-schema is data-oriented rather than form (ui), it is not very friendly for declaring a form.

For a form, care about what the form items are, what the form items look like, what are the validation rules, all these are related to the fields. The most intuitive management is in one place

Come to a simple comparison:

  • json-schema example:

json-schema sample

  • ncform example:

ncform schema sample

Json-schema for validation rules, declared in various places, not well managed. And ncform is concentrated in rules field. This design is also convenient for later development of form development IDE

dx expression:

With dx expressions, you can get the value of the specified field with {{$root.xxx}} and then write your arbitrary logical expression with the native JS.

  • Specify the attribute value in the object, for example:
disabled: 'dx: {{$root.person.age}} < 18'
  • Specify the value of an item in the array, for example:
disabled: 'dx: {{$root.persons[0].age}} < 18'
  • Specify the properties of the same item in the array, for example:
disabled: 'dx: {{$root.persons[i].age}} < 18'
disabled: 'dx: {{$root.persons[i + 1].age}} < 18'
  • Access constant data in the global configuration, for example:
disabled: 'dx: {{$root.person.age}} === {{$const.max}}'

// The global configuration is as follows
globalConfig: {
  constants: { max: 18 }
}

dx expressions can also be replaced with function :

function(formData, constData, selfData, tempData, itemIdxChain) { ... }

  • formData: corresponds to {{$root}}. Form data
  • constData: corresponds to {{$const}}. Constant data in global configuration
  • selfData: corresponds to {{$self}}. Used only for ui.preview.value, which refers to its own value
  • tempData: corresponds to {{$temp}}. Temporarily stored value
  • itemIdxChain: useful only for array items, refers to the index path of the current array, such as [1, 0]

Some common examples are as follows:

// form data
disabled: function(formData) {
  return formData.person.age < 18;
}

// array item
disabled: function(formData, constData, selfData, tempData, itemIdxChain) {
  const [ i ] = itemIdxChain;
  return formData.persons[i].age < 18;
}

// global constants
disabled: function(formData, constData) {
  return formData.person.age < constData.max;
}

Design Thinking

ncform = ncform container + ncform theme standard component

design

A system project generally uses a UI library (such as vue) and a UI implementation (such as elementui) In order to live in peace with it, ncform's standard components can use the same UI implementation

The ncform Vue version provides the standard components of the elementui theme by default [Click to view]

If you are a fan of iview, you can develop standard components of the iview theme by following the specifications of the ncform standard components.

Thought: "Throw in" the standard components of various themes into the ncform container, which is a nice tool for developing forms.

Schema Generator

You can accelerate the speed of writing form schemas with Schema Generator

Also you can try the third-party vscode extension: vscode-plugin-ncform-schema

References

Authors

  • Daniel.xiao : ncform designer and main implementer
  • Kyle.lo : The implementer of the ncform form validation part and the main developer of the standard component

Contributors

daniel.xiao
daniel.xiao

☺️
Kyleloh
Kyleloh

💻
liuxuewei
liuxuewei

💵
woodytechnology
woodytechnology

💵

Sponsor

ncform is an MIT licensed open source project and completely free to use. If it is useful for you, you can give me a cup of coffee :).

One-time donation

Monthly support

Become a backer or sponsor via Patreon

Contribution

See Contributing Guide.

ncform's People

Contributors

daniel-dx avatar dependabot[bot] avatar dylanxue avatar f-loat avatar gcaufy avatar gerard-szulc avatar kyleloh avatar littledu avatar photobylucas 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  avatar  avatar  avatar

Watchers

 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

ncform's Issues

关于组件通讯的问题

一个不太确定的问题,form-item 组件里是直接修改 schema.value,触发 ncform 里 watch dataFormSchema 的逻辑?

打包后无法正常使用

您好!我目前使用ncform的方式是,前端选择了某个模板,后端根据该模板需要填写的参数生成json返回给前端ncform,生成表单,在npm run dev的时候正常运行,但是在npm run build放进服务器里无法正常使用,只显示了一个空白的input框,想请问一下这个应该怎么解决呢?

Some questions

  1. There is a way to change the "Select Please" placeholder?

  2. How to attach a event listener that when some input is clicked, only the selected field schema is saved in a const? The thing is: I have a form editor where the user see a preview of the form, and my idea is that when the user click in one specific input he can edit it and see a preview only for the input, some idea in how to achieve this?

  3. How to translate the datepicker?

Help plz

Hi i write simple code, but he not worked. What is a mistake?

formSchema: {
          type: 'object',
          properties: {
            "choice": {
              "type": "number",
              "ui": {
                //hidden: true,
                "widget": "select",
                "widgetConfig": {
                  "clearable": true,
                  "enumSource": [
                    {
                      "value": 1,
                      "label": "option1"
                    },
                    {
                      "value": 2,
                      "label": "option2"
                    }
                  ]
                }
              }
            },

            "user": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "ui": {
                "hidden": "dx: {{$root.choice === 2}}",
                "widget": "array-table"
              }
            }
          }
        }

不使用的欄位key在送出表單後,key是否可設定不存在?

呈現方面,想要填寫A欄位,是依據B欄位選擇的值,進行使用與不使用的互動。

情境舉例:
openColor選擇Yes,color欄位顯示
openColor選擇No時,color隱藏。

但想詢問的是,
當openColor選擇No時,送出的值是否可移除color?期望送出值為{"openColor": false}

image

附上程式碼

Vue.use(vueNcform, { extComponents: ncformStdComps, /*lang: 'zh-cn'*/ });
    new Vue({
        el: '#demo',
        data: {
            formSchema: {
                type: 'object',
                properties: {
                    openColor:{
                        "type":"boolean",
                        "value":true,
                    },
                    "color":{
                        "type": "string",
                        "ui": {
                            "widget": "color-picker",
                            "hidden": "dx: {{$root.openColor}} === false"
                        },
                        "format": "color-picker"
                    }
                }
            }
        },
        methods: {
            submit() {
                this.$ncformValidate('your-form-name').then(data => {
                    if (data.result) {
                    var posts = this.$data.formSchema.value;
                    document.getElementById("result").innerHTML = JSON.stringify(posts, null, 2);
                }
            });
            }
        }
    });

dx表达式怎样取数组的最后一项内容

FileData字段的value如下

{
"FileNO":"",
"FileData":[
{
"status":"success",
"name":"图表_1.jpg",
"size":61338,
"percentage":100,
"uid":1559616801446
},
{
"status":"success",
"name":"图表_2.jpg",
"size":85091,
"percentage":100,
"uid":1559616810634
}
]
}

另外有个字段如 FileName,它的valueTemplate想关联显示上面数组最后一项的 name

1)如下面的写法能显示第一项的
valueTemplate: "dx: {{$root.UploadFile.FileData[0].name}}"

2)但我想显示最后一项,如下写法,则没有显示,请问是需要怎样编写
valueTemplate: "dx: {{$root.UploadFile.FileData[$root.UploadFile.FileData.length - 1].name}}"

3)如果是写成如下是能取到值的
valueTemplate: "dx: {{$root.UploadFile.FileData.length}}" or valueTemplate: "dx: {{$root.UploadFile.FileData.length}} - 1"

还有文档说明中的 i变量是什么意思?特定写法?
指定数组中同一项的属性,例子:
disabled: 'dx: {{$root.persons[i].age}} < 18'
disabled: 'dx: {{$root.persons[i + 1].age}} < 18'

谢谢

异步联动时,第二个select 多选错误

{
"type": "object",
"properties": {
"province": {
"type": "string",
"ui": {
"label": "省份",
"widget": "select",
"widgetConfig": {
"itemLabelField": "name",
"itemValueField": "id",
"enumSourceRemote": {
"remoteUrl": "/api/test/getProvinces",
"paramName": "keyword"
}
}
}
},
"city": {
"type": "array",
"ui": {
"label": "城市",
"widget": "select",
"widgetConfig": {
"itemLabelField": "name",
"itemValueField": "id",
"multiple": true,
"enumSourceRemote": {
"remoteUrl": "/api/test/getCities",
"paramName": "keyword",
"otherParams": {
"provinceId": "dx: {{$root.province}}"
}
}
}
}
}
}
}
如果city "multiple"属性为true,则会报错

Upload组件错误修正

control-comps/upload.vue 里 225 ,226行代码
fileList[i].name = resObj && resObj[fileUrlField] || fileList[i].name;
fileList[i].url = resObj && resObj[fileNameField] || fileList[i].url;
应该修正为
fileList[i].name = resObj && resObj[fileNameField] || fileList[i].name;
fileList[i].url = resObj && resObj[fileUrlField] || fileList[i].url;

是否可以简化v-model='schema.value'?

  <ncform :form-schema="formSchema" v-model="formSchema.value" :is-dirty.sync="isFormDirty"></ncform>

是否可以用指令简化 :form-schema="formSchema" v-model="formSchema.value"
类似于 这样?

  <ncform v-ncform="formSchema" :is-dirty.sync="isFormDirty"></ncform>
    Vue.directive("ncform", (el, binding, vnode) => {
      vnode.componentInstance.formSchema= binding.value;
      vnode.componentInstance.itemValue= binding.value.value;
      vnode.componentInstance.$on("input", payload => {
        binding.value.value = payload;
      });
    });

array-table

array-table 的删除有个提示就好了

required 检查 和 datePicker 控件clear逻辑有冲突

datePicker控件 clearable 打开, 并且设置该字段为required,
如果选择好日期以后再clear, 此时datePicker控件上无值, 但是可以通过required检查, 因为该字段的value经过clear后, 变成"0".
ncform-theme-elementui/src/components/control-comps/date-picker.vue 的_processModelVal方法吧, return之前检查一下newVal 是否为null, 是的话直接返回即可.

_processModelVal(newVal){ if(newVal == null){ return null; } return${new Date(newVal).getTime()}; }

date-picker能支持非时间戳样式的value吗,如 2019-06-02

目前widget为date-picker类型时,仅能传入时间戳类型,如1512284108066。

这样对于如 “2019-06-02” 或 “2019-06-02 12:20:30” 需要额外再转换一次

value: Date.parse('2019-4-10 08:12:30')

能否直接支持这样YYYY—MM-DD之类的传值?(例如传入一个转换格式符或判断不是时间戳就按日期格式来赋值)

希望增加Switch标准组件

Switch 也比较常用,希望能官方增加上。

这个组件没有那么复杂,自行写扩展也行,但是还要在自己项目中实现这种非特殊业务功能的标准组件,还要加上
Vue.use(vueNcform, { extComponents: Object.assign(ncformStdComps, { MyCustomComp }), extRules: [{ myCustom: MyCustomRule }], lang: "" // you can try 'en' or 'zh-cn' });

就有点怪怪的感觉。

还是希望官方能加上。谢谢

npm install安装不上

使用 npm i @ncform/ncform @ncform/ncform-common --save
安装不上,提示什么

npm ERR! path D:\Web\node_modules\chalk\node_modules\has-ansi
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall access
npm ERR! enoent ENOENT: no such file or directory, access 'D:\Web\node_modules\chalk\node_modules\has-ansi'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

用阿里的 cnpm 提示找不到

能否提供不带@的或CNPM的安装途径,谢谢?

无法安装 ncform-common

PS G:\1vue\fast> npm install --save @ncform/ncform ncform/ncform-common
npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\cmd\git.EXE ls-remote -h -t ssh://[email protected]/ncform/ncform-common.git
npm ERR!
npm ERR! Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.
npm ERR! [email protected]: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128

github上拉下来的各模块无法打出压缩包

github上拉去下来的各模块无法打出压缩包(min包)

原因是 conf/webpack.config.js
image

环境变量未配置

conf/webpack.config.prd.js 中加入DefinePlugin插件

new webpack.DefinePlugin({
   'process.env': {
      NODE_ENV: '"production"'
    }
})

横排布时,widget为label在multiLine时没有对齐

横排布时,widget为label在multiLine时没有对齐

        label2: {
          type: "string",
          value: "ncform, a nice form development way that generates form UIs and their interactions with just configuration.",
          ui: {
            columns: 12,
            widget: "label",
            label: '客户说明',
            widgetConfig: {
              multiLine: true
            }
          }
        },

效果如下图,虽然是设置为多行显示模式,但是当前内容是只需显示为一行,没有跟标签“客户说明”对齐,显示内容高了一点
image

但是当上面的多行显示设置为false时,即 multiLine: false ,显示是对齐的
image

我 觉得应该在多行模式时也要兼容只有一行的情况,跟标签平行对齐
最好调整一下,免得调用时要自行处理,谢谢。

是否可以做到关联表单项的数据获取逻辑

如题,需求是有三个select A 和 B、C,A选择了条目之后,会影响到B的choices,而A和B的choice,共同影响了C的choice,而这三块的数据获取都是相对独立的,请问这种情况该怎么处理?或者有什么好的改进思路吗?

谢谢。

可以异步设置数据吗?

你好,我现在有个需求。页面加载后,从 api 请求数据,并填充到 form 表单中不同 input,select 中。是否有一个异步设置数据的方法。不是使用 enumSourceRemote 这个配置。

array-tabs提供选项在增加tab时直接激活新tab

目前array-tabs,在增加一个item,tab的激活页还是第一页,这样有时不适合增加者的期望体验,会让人感觉到未增加成功,或者需要再点一下新增的tab才能激活并看到里面的内容,比较繁琐

image

如上图,点增加后,还是 user1保持激活,并不是user3,增加者看到的还是input里面的 1111内容,会误以为未增加成功的,或者要再点一下user3才能进行下一步

期望能增加一个选项,增加后直接激活新增的tab,谢谢

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.