AJAX Validation problem in Yii 1.1.9 episode 2

Since i’ve upgraded to version 1.1.9 AJAX validation stopped working (even JS validation).

The problem is similar to the one in this post: http://www.yiiframework.com/forum/index.php?/topic/27455-ajax-validation-problem-in-yii-119/

The post suggested a solution for the bug, however after making the modification the problem still persist.

The post was locked, that’s why I created this new one.

Any help would be greatly appreciated.

Thank you for your time and effort in advance.

Camino

There are few problems in the 1.1.9 version that are already fixed in the SVN trunk… did you try with the latest version from the trunk?

Hello mdomba,

Thank you for your reply.

I will try the newest trunk version, however my question is: how safe is it to run a trunk version ? I need a stable release as I’m building a relatively big application here :)

Thank you

Hello again,

Apperently i was using the lastest version.

First of all be sure that you deleted the content of the assets folder so that your app uses the latest JS code…

The problem you referred to in the first post has been fixed in the trunk… so if you use that version and still has problem… it’s not the same…

to get proper help you need to describe your problem… what you want to accomplish… what happens… what does not work… any error… your code… and so on…

I made sure to clear the asset folder.

Problem:

I have the model called User and an CActiveForm along side a view as a registration form.

I have several validation rules, such as:

username should be unique && min length=> 4

password should match password_confirm field && min length=>6

When working with version 1.1.8.r3324 when typing the username AJAX will notify me with an error msg if the length => 4 or if the username is already taken.

I downloaded 1.1.9.r3527, cleared the asset folder, renamed the old framework folder and pasted the new one.

AJAX validation stopped working.

I tried to manually modify framework/web/js/source/jquery.yiiactiveform.js to reflect the changes found at http://code.google.com/p/yii/source/detail?r=3530 in vain, problem persisted.

So now I’m back to the old version.

I also noticed that while the above mentioned rules works for the username, however whenever i type in a password with a lenght < 6, I get the following error "Password must be repeated exactly." which is for another rule o match 2 passwords fields.

Any ideas would be mush appreciated.

Again that you for your time.

So now I’m back to the version 1.1.8.r3324 until i find a solution

hints:

1- no errors shown, neither in the apache log file nor in the browser.

2- when working in with version 1.1.9.r3527, i opened up firebug and monitored the Net panel for any AJAX request/replies. none where found.

I did not understand if the username validation works completely or not…

So with the 1.1.9 version there are no AJAX calls made at all ? That should work for sure in 1.1.9… if "enableAjaxValidation" is set to true…

btw

There are more changes to the activeform.js file after the r3538…

the best would be to try with the complete checkout from the google code…

to help you more I would need to see your view file, the rules and the controller action

i downloaded the latest jquery.yiiactiveform.js you modified in the trunk, i confirm it’s working :)

as for the password error, I moved the rule array(‘password’, ‘length’, ‘min’=>6 , ‘max’=>255), to appear before array(‘password’,‘compare’,‘compareAttribute’=>‘confirm_password’), it’s working now.

However the following error error is still present:

I have 2 fields in my form:

&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'password'); ?&gt;


	&lt;?php echo &#036;form-&gt;passwordField(&#036;model,'password',array('size'=&gt;60, 'maxlength'=&gt;255)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'password'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'confirm_password'); ?&gt;


	&lt;?php echo &#036;form-&gt;passwordField(&#036;model,'confirm_password',array('size'=&gt;60,'maxlength'=&gt;255)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'confirm_password'); ?&gt;


&lt;/div&gt;

When i enter the password in the first field, I get this error: Password must be repeated exactly.

So i jump to the 2nd field to enter the same password, yet the error never gets away even when the field turn to green (accepted).

Could this be another bug where ajax fails to update the css ?

Thank you again for your time Sir.

We are talking about the AJAX validation right?

On ajax validation only the current input field is updated… so

When you leave the first field… the validation is fired… as the second field is empty… the validation fails and the error is shown for the first field…

but when you leave the second field even if validation pass the first field will not get updated…

to solve this… you can set the validation rule for the second field … so that the user would get the error only when leaving the second field (if the values are different)

I was just thinking about doing that, it is working like a charm !!!! PERFECT ! Again & again thank you so mush Sir for your time and effort, mush appreciated :)

Thank you for testing the new fixes in the trunk version :D

[size="2"][size="2"]I still have an error with the lastest revision r3538[font="arial, sans-serif"], the chrome console throw the following error:[/font][/size][/size]

[font="arial, sans-serif"] [/font][font="arial, sans-serif"]

[size=“2”]Uncaught TypeError: Cannot read property ‘tagName’ of undefined[/size]

[size="2"]getAFValue - jquery.yiiactiveform.js:20[/size]

[size="2"]$.fn.yiiactiveform.each.settings.submitting - jquery.yiiactiveform.js:59[/size]

[size="2"]e.extend.each - jquery.min.js:2[/size]

[size="2"]$.fn.yiiactiveform - jquery.yiiactiveform.js:46[/size]

[size="2"]e.extend.each - jquery.min.js:2[/size]

[size="2"]e.fn.e.each - jquery.min.js:2[/size]

[size="2"]$.fn.yiiactiveform - jquery.yiiactiveform.js:39[/size]

[size="2"](anonymous function) /cms_base/public_html/index.php?r=msadmin/access:96[/size]

[size="2"]f.Callbacks.n - jquery.min.js:2[/size]

[size="2"]f.Callbacks.o.fireWith - jquery.min.js:2[/size]

[size="2"]e.extend.ready - jquery.min.js:2[/size]

[size="2"]c.addEventListener.B - jquery.min.js:2[/size] [/font]

[font="arial, sans-serif"]

[/font]

[font="arial, sans-serif"]

[/font][size="2"][font="Consolas,"]and this is my form:[/font][/size][size="2"][font="Consolas,"]

[/font][/size][size="2"][font="Consolas,"]




 <h2><?php echo Yii::t('login', 'SYSTEM ACCESS'); ?></h2>[/size]

                    <?php

                        /* @var $form CActiveForm */

                        $form = $this->beginWidget('CActiveForm', array(

                                'id' => 'login-form',

                                'enableClientValidation' => true,

                                'clientOptions' => array(

                                    'validateOnSubmit' => true

                                )

                            )

                        );

                    ?>

                    <?php echo !$form->error($model, '_main', array('class'=>'messagebox error'))?>

                    <div class="row">

                        <?php echo $form->labelEx($model, 'username'); ?>

                        <?php echo $form->textField($model, 'username', array('class'=>'tf')); ?>

                        <?php echo $form->error($model, 'username'); ?>

                    </div>


                    <div class="row">

                        <?php echo $form->labelEx($model, 'password'); ?>

                        <?php echo $form->passwordField($model, 'password', array('class'=>'tf')); ?>

                        <?php echo $form->error($model, 'password'); ?>

                    </div>




                    <div class="row buttons">

                        <?php echo CHtml::submitButton(Yii::t('login','LOGIN'), array('class'=>'chunky', 'id'=>'ms-loginBtn')); ?>

                    </div>


                    <?php $this->endWidget(); ?>[/font][/size]

[size="2"][font="Consolas,"]

[/font][/size][size="2"][font="Consolas,"]

[/font][/size][size="2"][font="Consolas,"]The weird thing is that it works in v1.1.8[/font][/size]

[size="2"][font="Consolas,"][/font][/size][size="2"][font="Consolas,"]

[/font][/size][size="2"][font="Consolas,"]Thanks in advice for your help.

[/font]

[/size]

check if you have the latest version (did you clean the assets folder?)… as the line numbers in the error log do not mach the actual file

for example the getAFValue function is on line 18 not on 20… and tagName is checked on line 24.