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

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
Assignees
Labels
Milestone

Comments

@teo1978
Copy link

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.

@ErikMinekus
Copy link

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.

@mdomba
Copy link
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 added a commit that referenced this issue Nov 21, 2012
CCompareValidator supported {compareAttribute} in $message only
server-side
@cebe
Copy link
Member

cebe commented Nov 21, 2012

fixed with 54c71d5.

@cebe cebe closed this as completed Nov 21, 2012
@cebe
Copy link
Member

cebe commented Nov 21, 2012

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

@cebe cebe reopened this Nov 21, 2012
cebe added a commit that referenced this issue Nov 21, 2012
@cebe cebe closed this as completed Nov 21, 2012
@mdomba
Copy link
Member

mdomba commented Nov 21, 2012

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

compareValue should hold the value

@mdomba mdomba reopened this Nov 21, 2012
@cebe
Copy link
Member

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.

@cebe
Copy link
Member

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.

@mdomba
Copy link
Member

mdomba commented Nov 21, 2012

check the line 163 -

$compareValue="jQuery('#" . (CHtml::activeId($object, $compareAttribute)) . "').val()";

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

@cebe
Copy link
Member

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
Copy link
Member

cebe commented Nov 21, 2012

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

@cebe cebe closed this as completed Nov 21, 2012
cebe added a commit that referenced this issue Nov 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants