im using a CHtml::ajaxSubmitButton , the button is working proper, data is saving… but after refresh the submitted value is displying there on the textField…the textField is not refreshing… how to implement that… ?
im using a CHtml::ajaxSubmitButton , the button is working proper, data is saving… but after refresh the submitted value is displying there on the textField…the textField is not refreshing… how to implement that… ?
What’s the code for submit button + textfield?
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'activity-action-comments-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'action_id'); ?>
<?php echo $form->hiddenField($model,'action_id',array('value'=>'2')); ?>
<?php echo $form->error($model,'action_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'user_id'); ?>
<?php echo $form->hiddenField($model,'user_id',array('value'=>'1')); ?>
<?php echo $form->error($model,'user_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'date'); ?>
<?php echo $form->hiddenField($model,'date',array('value'=>date('Y-m-d'))); ?>
<?php echo $form->error($model,'date'); ?>
</div>
<div class="row" id="textareaId1">
<?php echo $form->labelEx($model,'comment'); ?>
<?php echo $form->textField($model,'comment',array('id'=>'textareaId1')); ?>
<?php echo $form->error($model,'comment'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::ajaxSubmitButton("Create",
CController::createUrl('ActivityActionComments/create'),
array(
'success'=>'function(){
$(#textareaId1).val(\"\")
}',
),
array('id' => 'ajaxButton'));
?>
<?php $this->endWidget(); ?>
Try this
<script language="javascript">
function updateFileName(){
$('#textfld').val("");
}
</script>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'activity-action-comments-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'action_id'); ?>
<?php echo $form->hiddenField($model,'action_id',array('value'=>'2')); ?>
<?php echo $form->error($model,'action_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'user_id'); ?>
<?php echo $form->hiddenField($model,'user_id',array('value'=>'1')); ?>
<?php echo $form->error($model,'user_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'date'); ?>
<?php echo $form->hiddenField($model,'date',array('value'=>date('Y-m-d'))); ?>
<?php echo $form->error($model,'date'); ?>
</div>
<div class="row" id="textareaId1">
<?php echo $form->labelEx($model,'comment'); ?>
<?php echo $form->textField($model,'comment',array('id'=>'textfld')); ?>
<?php echo $form->error($model,'comment'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::ajaxSubmitButton (
Yii::t('forms','Create'),
CController::createUrl('ActivityActionComments/create'),
array(
'type' =>'POST',
'success' => 'function() updateFileName()', ) ); ?>
</div>
<?php $this->endWidget(); ?>
yeah… its working… Thank u very much.
please share action controller for this ajax code !
you only missed single quotes in $(#textareaId1)
<?php echo CHtml::ajaxSubmitButton("Create",
CController::createUrl('ActivityActionComments/create'),
array(
'success'=>'function(){
$(\'#textareaId1\').val(\'\')
}',
),
array('id' => 'ajaxButton'));
?>
@abedi98 : you can use Gii’s generated codes with no modification at all, just replace CHtml::submitButton with ajaxSubmitButton.
CMIIW.