arnold_p
arnold_p

Reputation: 505

Set Field Empty When Change Password in Yii

I want to set empty this field: enter image description here

This is my code from _form.php

<div class="row">
    <?php echo $form->labelEx($model,'password'); ?>
    <?php echo $form->passwordField($model,'password',array('size'=>50,'maxlength'=>50)); ?>
    <?php echo $form->error($model,'password'); ?>
</div>

how to that, please teach me. Thanks all

Upvotes: 1

Views: 2632

Answers (4)

Sarvar Nishonboyev
Sarvar Nishonboyev

Reputation: 13110

echo CHtml::passwordField('User[password]','')

Upvotes: 0

Iswanto San
Iswanto San

Reputation: 18569

This strange behaviour is happen for me too.

I fix it with javascript code to set the password field value to empty.

Yii code:

    <div class="row">    
        <?php echo $form->labelEx($model,'newpassword'); ?>
        <?php echo $form->passwordField($model,'newpassword',array('size'=>60,'maxlength'=>128,'value'=>'')); ?>
        <?php echo $form->error($model,'newpassword'); ?>
    </div>

Javascript code (I am using jQuery) :

<script>
  $(document).ready(function()
  {
    $("#ChangePasswordForm_newpassword").val("");
  });
</script>

Upvotes: 0

DaSourcerer
DaSourcerer

Reputation: 6606

You can explicitly set the value to be an empty string like this:

<?php echo $form->passwordField($model,'password',array(
    'size'=>50,
    'maxlength'=>50,
    'value'=>'',
)); ?>

Upvotes: 1

Joe Miller
Joe Miller

Reputation: 3893

Where you are starting your form, you can add htmlOptions like this;

        'htmlOptions' => array(
            'autocomplete' => 'off'
        )

This will disable autocomplete for the whole form. If you just want to do it for a single field, add it to the htmlOptions for that file instead.

Upvotes: 1

Related Questions