Skip to content

CActiveForm: Updating password_repeat field doesn't trigger client side compare validation #1925

Closed
nsanden opened this Issue Jan 5, 2013 · 7 comments

6 participants

@nsanden
nsanden commented Jan 5, 2013

I assume thats because my rule is:
array('password', 'compare', 'compareAttribute'=>'password_repeat')

and that only triggers when the 'password' field is changed.

I also tried adding another rule:
array('password_repeat', 'compare', 'compareAttribute'=>'password')

but that didnt seem to do the trick.

Here's same/similar report.
http://stackoverflow.com/a/11938705

@rusmaxim
rusmaxim commented Jan 5, 2013

I use afterValidateAttribute event.

'afterValidateAttribute' => 'js:function(form, attribute, data, hasError) {
     if (attribute.name == "confirmPassword") {

        var settings = $.fn.yiiactiveform.getSettings(form);
        successCallback = function (messages) {
            $.each(settings.attributes, function () {
                if (this.name == "password") {
                    $.fn.yiiactiveform.updateInput(this, messages, form);
                }
            });
        };

        $.each(settings.attributes, function () {
            if (this.name == "password") {
                this.status = 2;
            }
        });

        $.fn.yiiactiveform.validate ("#login-form", successCallback);
    }
}'

May be add in jquery.yiiactiveform.js function
$.fn.yiiactiveform.validateAttribute (form, attribute) {
}
to validate and update attribute?

then we can use

'afterValidateAttribute' => 'js:function(form, attribute, data, hasError) {
     if (attribute.name == "confirmPassword") {
         $.fn.yiiactiveform.validateAttribute (form, "password");
    }
}'
@cebe cebe was assigned Jan 9, 2013
@adminnu
adminnu commented Jan 22, 2013

and that only triggers when the 'password' field is changed.
I also tried adding another rule:
array('password_repeat', 'compare', 'compareAttribute'=>'password')

It will not work, because it requires that you run upgrade validation checks in the first field, when the second one, in your case, they simply compare themselves.
I'm doing this thing, but a lot of difficulties.
comment: #1910 (comment)

@mdomba mdomba was assigned Jan 22, 2013
@mdomba
Yii Software LLC member
mdomba commented Jan 22, 2013

Isn't this a duplicate of #1528

@nsanden
nsanden commented Jan 22, 2013

@mdomba - you are right, this is a duplicate, as is #1910 @qiangxue - please reconsider. maybe we just need a fix for allowing a second compare rule, to compare password_repeat with password

@adminnu
adminnu commented Jan 22, 2013

I'm working on this issue. When you work it will not be to validate each attribute in #1528, but only to compare.
Today or tomorrow I will send a pull.

@mdomba
Yii Software LLC member
mdomba commented Jan 23, 2013

@nsanden please check this comment - #2026 (comment)

@cebe cebe modified the milestone: 1.1.16, 1.1.17 Aug 15, 2014
@samdark samdark closed this Nov 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.