Hello nice people, I'm pretty new to the 'Yii' platform, however, I have searched all over the internet for a solution to my problem as I have had a roadblock on this for 3 days (believe it). I have a created form to receive employee data from user input. I have a 'textField' for password but my intention is to auto-generate this password using a custom method call. This call will initially fill the 'textField' automatically upon page load and subsequently require the use of 'ajaxButton' to re-generate a new password.
As it stands, the method is located in my Model, while my controller is set-up to manage the request and 'renderPartial' the targeted view upon the ajax request. Issue is, I have successfully achieved the effect because I can see the auto-generated value appear on a targeted 'div' in my form. However I want this value to appear within the 'textField' marked with a "password" attribute. Any ideas how I can achieve this, a clear and concise implementation will be appreciated as am still new to this MVC approach and not the best with javaScript either.
the code below
----Model----
---- Employee.php ---
//Method for generating password in Employee Model
--- form ----
--- _form ---
//this code actually gets the value and updates the targeted div ('pass') as desired
<div class="row" >
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->textField($model,'password',array( 'id'=>"passwd", 'name'=>'passwd')); ?>
<?php echo $form->error($model,'password'); ?>
<?php echo CHtml::ajaxButton('Generate',array('randomize'),array( 'update'=>'#pass', )); ?>
</div> <div id='pass'></div>
// this is the alternate code i was hoping will actually target the textField ('password') and change its value
// as desired
<div class="row" >
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->textField($model,'password',array( 'id'=>"passwd", 'name'=>'passwd')); ?>
<?php echo $form->error($model,'password'); ?>
<?php echo CHtml::ajaxButton('Generate',array('randomize'),array( 'update'=>'#pass',
'data'=>array('password'=>'js: { $(\'#passwd\').val()}'))); ?>
</div> <div id='pass'></div>
Updating Textfield Value From Custom Method Call Through Ajaxbutton
in The Yii Book
Posted