javascript - avalon validator.validate is not a function

查看:202
本文介绍了javascript - avalon validator.validate is not a function的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

<!DOCTYPE html>
<html>
    <head>
        <title>ms-validate</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
        <script src="avalon.js"></script>
        <script>
            avalon.validators.aaa = {
                message: '必须数字并大于0',
                get: function (value, field, next) {
                   //想知道它们三个参数是什么,可以console.log(value, field,next)
                    var ok = (value === '' || (Number(value) > 0))
                    next(ok)
                    return value
                }
            }
            var vm = avalon.define({
                $id: "test",
                aaa: '',
                validate: {
                    onError: function (reasons) {
                        reasons.forEach(function (reason) {
                            console.log(reason.getMessage())
                        })
                    },
                    onValidateAll: function (reasons) {
                        if (reasons.length) {
                            console.log('有表单没有通过')
                        } else {
                            console.log('全部通过')
                        }
                    }
                }
            })
        </script>
    </head>

    <body ms-controller="test">
        <form class="cmxform" ms-validate="@validate" >
            <fieldset>
                <legend>自定义规则</legend>
                <p>
                    <input 
                        ms-duplex="@aaa"
                        ms-rules="{aaa: true}" 
                        >
                </p>
            </fieldset>
            <p>
                <input class="submit" type="submit" value="提交">
            </p>
        </fieldset>
    </form>
</body>
</html>

解决方案

可能是你的插件的版本的问题, 我这里报了这个错, 在鼠标focus文本框的时候, 报错

 <script src="https://cdnjs.cloudflare.com/ajax/libs/avalon.js/2.2.0/avalon.js"></script>

用的是官网最新版

这篇关于javascript - avalon validator.validate is not a function的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆