CCompareValidator supports {compareAttribute} in $message only server-side (undocumented) and not on client side #1621

Closed
teo1978 opened this Issue Oct 27, 2012 · 10 comments

Comments

4 participants

teo1978 commented Oct 27, 2012

CCompareValidator->message should accept a {compareAttribute} placeholder for the name of the attribute it compares to.

Actually, it does (and this is not mentioned in the documentation) but only on server side validation.

Client side validation forgets to replace the {compareAttribute} placeholder.

Client side validation should always be absolutely identical to server side validation for all builtin validators.

Problem is in https://github.com/yiisoft/yii/blob/1.1.12/framework/validators/CCompareValidator.php#L207

I guess adding '{compareAttribute}'=>$compareTo will fix the issue, though it may be a little bit more subtle.

The fact that the documentation doesn't mention this placeholder is actually a good thing until this is fixed, however this placeholder is absolutely necessary.

This was added in 0f9f1e5 (issue #515), but the pull request was closed. It actually looks more like a bug, {compareValue} contains the attribute label of compareAttribute while it should contain the value being compared with, just like in the server-side validation.

cebe was assigned Nov 20, 2012

Member

mdomba commented Nov 21, 2012

Really can't remember why I closed the #515 issue...

@ErikMinekus is right in clientValidation compareValue gets the label instead of the value like on server-side, compareAttribute should be added for the client and it shoudl be mentioned in the documentation

setting this to Easy Pick...

@cebe cebe added a commit that referenced this issue Nov 21, 2012

@cebe cebe fixed issue #1621
CCompareValidator supported {compareAttribute} in $message only
server-side
54c71d5
Owner

cebe commented Nov 21, 2012

fixed with 54c71d5.

cebe closed this Nov 21, 2012

Owner

cebe commented Nov 21, 2012

Reopening since travis build failed: https://travis-ci.org/yiisoft/yii/jobs/3299637

cebe reopened this Nov 21, 2012

@cebe cebe added a commit that referenced this issue Nov 21, 2012

@cebe cebe Fix issue #1621 8f7931b

cebe closed this Nov 21, 2012

Member

mdomba commented Nov 21, 2012

But now compareAttribute and compareValue holds the same info - the label

compareValue should hold the value

mdomba reopened this Nov 21, 2012

Owner

cebe commented Nov 21, 2012

Nope, this depends on whether you are comparing with a fixed value or with an other attribute.
It is still a bit different to server behavior but we can not set compareValue to the correct value on clientValidation when we compare with an other attribute rather then with a fixed value.

Owner

cebe commented Nov 21, 2012

When you use {compareAttribute} in message when comparing with an attribute and {compareValue} when comparing with a fixed value everything is fine. Problems might occur when you mix them, which does not make sense imho.

Member

mdomba commented Nov 21, 2012

check the line 163 - https://github.com/yiisoft/yii/blob/8f7931b019f910a04f0dc7f2deeed40d18cc2bf4/framework/validators/CCompareValidator.php#L163

we already have the JS code that gets the actual compareTo value.

Owner

cebe commented Nov 21, 2012

Sure, but we can not use strstr to get that value into the message. Do you have a solution how to do this in JS?

@cebe cebe added a commit to cebe/yii that referenced this issue Nov 21, 2012

@cebe cebe Attempt to make clientValidation and Servervalidation to behave the s…
…ame for CCompareValidator

issue #1621
b921702
Owner

cebe commented Nov 21, 2012

finally fixed with #1740. Server and client messages are now the same.

cebe closed this Nov 21, 2012

@cebe cebe added a commit that referenced this issue Nov 21, 2012

@cebe cebe more on #1621 make server and client message the same
and DRY! :)
05a9123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment