avalon.oniui icon indicating copy to clipboard operation
avalon.oniui copied to clipboard

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

Open wonderbeyond opened this issue 10 years ago • 2 comments

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
            }
        },

wonderbeyond avatar Jul 25 '15 08:07 wonderbeyond

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

RubyLouvre avatar Jul 25 '15 12:07 RubyLouvre

@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, 表示允许的最大值

wonderbeyond avatar Aug 04 '15 01:08 wonderbeyond