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

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

Closed
RoyceWang opened this Issue Jan 24, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@RoyceWang
Copy link

RoyceWang commented Jan 24, 2018

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 ) )

@niceue niceue closed this in 7e2bccd Mar 11, 2018

@niceue niceue added the bug label Mar 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment