Coder Social home page Coder Social logo

formbuilder's Introduction

FormValidation 表單驗證

想法

  • 透過JSON配置,簡化/統一表單欄位設定
  • 監聽檢查、連動檢查,可用於複雜表單
  • JSON可前/後端共用(後端驗證模組另外寫)

TODO

  • 待處理物件
  • 客製化表單(custom select)
  • 創建 create()

Usage

formValidation.init(formID, settingJson);

驗證資料模板

var settingJson = {
  demo: {
    text: 'DEMO', // 文字說明
    type: 'text', // 欄位屬性
    defaultValue: null, // 預設值
    placeholder: null, // 提示訊息
    autocomplete: null, // 自動完成
    // 規則
    rule: {
      required: false, // 必填
      minimum: null, // 字元下限
      maximum: null, // 字元上限
      regex: null, // 驗證格式
      equality: null, // 與..相符
      onlyOne: false, // 只能選擇一個 [多選框選項]
    },
    // 客製化訊息 (取代規則預設訊息)
    msg: {
      required: null,
      minimum: null,
      maximum: null,
      regex: null,
      equality: null,
      onlyOne: null,
    },
    // 顯示條件
    conditions: [
      {
        triggerID: 'babyNum',
        findOne: ['1', '2', '3', '4'], // 滿足其一
        findAll: ['1', '2', '3', '4'], // 滿足全部
        // other...
      },
      // multiple..
    ],
    // 其他檢查設定
    requiredSync: [], // 連動必填元素 (如果自身有值,其元素必填)
    requiredCheck: [], // 自身必填檢查 (來自其他元素的 requiredSync)
    equalityReverseCheck: [], // 反向相符檢查 元素值是否相符 (來自其他元素的 rule.equality)
  },
}

formbuilder's People

Contributors

alanlu-zyl avatar

Watchers

James Cloos avatar  avatar

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.