Yii Framework Forum: Hide / Show Validation On Input Blur / Focus - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Hide / Show Validation On Input Blur / Focus active forms custom validation Rate Topic: -----

#1 User is offline   florin p 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 25-September 11

Posted 26 February 2013 - 03:30 PM

Hi all,

Currently I have this form:

 <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'user-login-form',
        'enableAjaxValidation' => true,
        'enableClientValidation' => false,
        'clientOptions' => array(
            'validateOnSubmit' => true,
        )
      ));
    ?>

        <div class="row">
            <label for="username" class="required">Username</label>
            <?php echo $form->textField($model, 'username', array())); ?>
            <?php echo $form->error($model, 'username'); ?>
        </div>
        <div class="row">
            <label for="password" class="required">Password</label>
            <?php echo $form->passwordField($model, 'password', array()); ?>
            <?php echo $form->error($model, 'password'); ?>
        </div>
        <div class="actions">
            <?php echo CHtml::submitButton(t('site', 'Enter'), array('class' => 'bGreenB')); ?>
        </div>

        <?php $this->endWidget(); ?>


I'm trying to hide the current error on its input focus and show the input error(if exists) on blur.
This is what I have so far:

<script type="text/javascript">
    
    $(document).ready(function() {

        $("#UserLoginForm_username").blur(function(){
                $(this).parent('.row').find('div.errorMessage').css('display', 'block');
           
        });
        
        $("#UserLoginForm_username").focus(function(){
            $(this).parent('.row').find('div.errorMessage').css('display', 'none');
        });
      
    });
</script>


The problem comes on blur event, the error will keep showing up even the input was correctly completed.
Any idea how to solve this problem?
0

#2 User is offline   florin p 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 25-September 11

Posted 03 March 2013 - 10:45 AM

Fixed,

Changed to afterValidateAttribute:

 'afterValidateAttribute' => 'js:function(form, attribute, data, hasError){
   $("#"+attribute.id).live("focus",function(){
    // do action here
   }
    $("#"+attribute.id).live("blur",function(){
    // do action here
   }
}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users