yii onchange ajax validation issue(cleared)


I was working the yii project in which i have update form ,where the data are  populated from controller to view allow model data to controller render function in yii.I had reset button in which default worked ,but as i update the form empty madtory field raised validation issue as i clicked the reset button it didnt restored the mandatory field.so assigned copy model varible by calling  findByPk

Eg:

Controller:
$id = $_REQUEST['id'];
$modelular= Milestones::model()->findByPk($id);
$this->render('update',array(
 'model'=>$model,
 'users'=>$Users,
 'allowEdit'=>$allowEdit,
 'copymodel'=>$copymodel,
 ));
View:
javascript function to reset the update form.
 $("#resetform").click(function(e) {
 e.preventDefault();//used rectifier the jquery issue
 $(".errorMessage").text("");
 $(".errorMessage").hide();
 $(".betterform").removeClass("error")
 $(".required").removeClass("error")
 // $("#milestones-form").trigger('reset');
 $("#Milestones_milestone_title").val("<?php echo $copymodel->milestone_title; ?>");
 $("#Milestones_milestone_description").val("<?php echo $copymodel->milestone_description; ?>");
 $('#Milestones_milestone_startdate').datepicker('setDate', "<?php echo date('d-m-Y',strtotime($copymodel->milestone_startdate));?>");
 $("#Milestones_milestone_duedate").datepicker('setDate', "<?php echo date('d-m-Y',strtotime($copymodel->milestone_duedate));?>");
 });

Onchange Issue:

Then comes the testing department issue that form does hides the validation msg after filling the input fields.

Controller:
just added code in controller function.
 $this->performAjaxValidation($model);
View :
<?php $form=$this->beginWidget('CActiveForm', array(
 'id'=>'milestones-form',
 'enableAjaxValidation'=>true,
 'enableClientValidation'=>true,
 'clientOptions'=>array(
 'validateOnChange'=>true,
),
)); ?>

<?php
 echo $form->textField($model,'milestone_title',array('class'=>'betterform','style'=>'width:95%','maxlength'=>100,'tabindex'=>1));
 // echo CHtml::label(Yii::t('milestones','FormMilestoneTitle'), CHtml::activeId($model, 'milestone_title'), array('class'=>'labelhelper'));
 echo $form->error($model,'milestone_title',array('validateOnChange'=>true));
 ?>
Advertisements
About

myself pramodh kumar yet another php developer from India and have worked on oops,procedural,yii framework,codeigniter,wordpress,joomla,api and more.

Tagged with: , , , , , , , , , , , ,
Posted in yii framwork

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow php tutorial on WordPress.com
categories
Calendar
May 2015
M T W T F S S
« Apr   Jun »
 123
45678910
11121314151617
18192021222324
25262728293031
Follow me on Twitter
Blog Stats
  • 74,607 hits
%d bloggers like this: