Skip to content

Bug of rule "match" with "display" options (match规则与display同用时的bug) #267

@RoyceWang

Description

@RoyceWang

When use rule "match" with a custom display function such as:
(当同时使用match规则和自定义display方法时,如下:)

fields:{
"current_value":{rule:"required;integer[+0];"},
"init_value":{rule:"required;integer[+0];match[lte, current_value];"}
},
display:function(element){
return $form.find("label[for='" + element.id + "']").text();
},
......

And I defined the message template as "{0} can not be greater than {1}!"
(并且,我定义了match lte的校验消息为"{0}不能大于{1}!")
But the validation failed message will be like:
"Init value can not be greater than Init value!"
(但是,校验出错提示消息显示为:
“初始值不能大于初始值!”)

I read the source code and found the message process function may have a little bug:
(我检查了源代码,发现有一处可能有一点点bug:)
At line 1872 in "nice-validator-1.1.3\src\jquery.validator.js":
(在"nice-validator-1.1.3\src\jquery.validator.js"第1872行:)
me.messages.match[type].replace( '{1}', me._getDisplay( element, field2.display || key ) )

I think it should not to replace the '{1}' token with display text generated from elment with belongs to current element.
(我想这里不应该把'{1}'占位符替换为当前元素的display文本值。)
It should use the display text generated from the target element. That is:
(而应该替换成要比较的目标元素的display文本值,如下:)
me.messages.match[type].replace( '{1}', me._getDisplay( elmt2, field2.display || key ) )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions