11 Star 17 Fork 3

/ formModel.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

#支持自动映射、自动验证和自动完成的表单模型类 这是一款拥有类似于后端thinkphp的“三大自动”前端表单模型

var RegModel = formModel.extend({
    $v: function(){
        return [
            ["username", "require", "请输入用户名。"],
            ["username", [6, null], "用户名长度过短,请限制在6-20个字节,1个汉字为2个字节。", "lengthAt"],
            ["username", [null,20], "用户名长度过长,请限制在6-20个字节,1个汉字为2个字节。", "lengthAt"],
            ["username", /\d{5}/,   "用户名中不能包含多个数字,推荐使用中文用户名。", "!regexp"],

            ["email",    "require", "请输入邮箱地址。"],
            ["email",    "email",   "邮箱地址格式有误。"],

            ["password", "require",            "请设置密码。"],
            ["password", /^[a-zA-Z]+$/,        "密码不能为纯字母。", "!regexp"],
            ["password", /^\d+$/,              "密码不能为纯数字。", "!regexp"],
            ["password", /^_+$/,               "密码不能为纯符号。", "!regexp"],
            ["password", /^[_0-9a-z]{6,20}$/i, "密码为6-20个字符,请使用字母加数字或下划线组合密码。"],

            ["repassword", "require",  "请输入确认密码。"],
            ["repassword", "password", "两次密码不匹配。", "confirm"]
        ]
    }
});

##License formModel.js遵循MIT协议发布


##更新日志

1.2.1

  • 新增error属性支持使用闭包设置动态错误信息,该闭包将接收到两个参数(name与value),必须返回一个字符串

1.2.0

  • 新增对批量验证的支持
  • check方法优化,用法有变,name参数与err合并,解决设置“空错误信息”导致判断出错的问题,check用法详情doc.md
// 升级到1.2.0方法:由于check有变,因此原function(err, name, callback)变更为function(err, callback),通过err.msg获取错误信息,err.name获取引发错误的字段
var m = formModel.create({......});
$("form").submit(function(){
    m.check(formModel.serializeObject(this), function(err, data){
        if(err){
            alert(err.msg);
            $("input[name="+err.name+"]").focus();
        }else{
            $.ajax({
                url: "......",
                data: data      // 此处的data可以直接使用回调中接收到的data
                success: function(){......}
            })
        }
    });
    return false;
});

1.1.0

  • 更完善的“自动完成”功能 自动完成功能用法略有变化,但原版的用法依然支持,原版用法视为简洁法,新版支持使用数组进行更完善的设置,详情doc.md
The MIT License (MIT) Copyright (c) 2015 楚 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

类似于thinkphp模型三大自动(自动映射、自动验证、自动完成)的前端表单模型,可以简洁地完成最常见的基础表单验证 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/luchg/formModel.js.git
git@gitee.com:luchg/formModel.js.git
luchg
formModel.js
formModel.js
master

搜索帮助