Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

校验规则ms-duplex-gt与它需要的参数max存在语义矛盾, 而且与浏览器默认校验规则冲突 #682

Open
wonderbeyond opened this issue Jul 25, 2015 · 2 comments

Comments

@wonderbeyond
Copy link

ms-duplex-gt规则使用max属性的值来作为 最小值 参数, 语义是不是反了, 应该用 min 吧?

我当时没有继续纠结, 就这样用了:

<input type="number" ms-duplex-gt="amount" max="100" />

但是后来发现这与浏览器自己语义是冲突的(针对input[type=number]), 比如在chrome里面, 向上滚动鼠标的时候最大能输入的值就是max指定的值, 与avalon.validation的语义正好相反.

附avalon.validation的gt相关实现:

        gt: {
            message: '必须大于{{max}}',
            get: function(value, data, next) {
                var elem = data.element
                var a = parseInt(elem.getAttribute("max"), 10)
                if (!isFinite(a)) {
                    a = parseInt(elem.getAttribute("data-duplex-gt"), 10)
                }
                var num = data.data.max = a
                next(parseFloat(value) > num)
                return value
            }
        },
@RubyLouvre
Copy link
Owner

好像是这样,这下惨了,业务已经在用了,改不了

@wonderbeyond
Copy link
Author

@RubyLouvre 如果由于业务风险不便于改, 建议后续版本保留现有用法, 但是要把 ms-duplex-gtDeprecated, 从文档中隐藏, 并运行时警告, 然后使用其它替代实现.

我为什么这么建议呢, 因为 max, min 这些属于input的标准属性, 当使用场景多的时候冲突就会很难避免.

至于用什么替代呢, 下面是我的建议:

  • ms-duplex-gt => ms-duplex-exceed, 表示要超过的值
  • ms-duplex-lt => ms-duplex-under, 表示要低于的值
  • ms-duplex-gte => ms-duplex-min, 表示允许的最小值
  • ms-duplex-lte => ms-duplex-max, 表示允许的最大值

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants