Yii Framework Forum: Implement Next/previous Buttons For _Form View - Yii Framework Forum

Jump to content

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

Implement Next/previous Buttons For _Form View Rate Topic: -----

#1 User is offline   Zeke 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-February 12

Posted 28 February 2013 - 03:33 PM

I have a customer that wants to be able to move to the next record in the database while in the _form view. This would be convenient for making updates to lots of records without having to always go back to the list view to select the next record.

I have the controller fetching the next record into a model and then I try to re-render the _form view with the new data and nothing changes. The model is getting to the _form.php but is not getting rendered on the page. I have used render(), renderPartial() and redirect() without any success.

If anyone has done this I would like some pointers on making this happen. It seems like it should be pretty strait forward but I can't seem to make it work.

Thanks for any help,

Zeke
0

#2 User is offline   lubosdz 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 115
  • Joined: 25-July 10
  • Location:Slovakia, Bratislava

Posted 28 February 2013 - 04:27 PM

What widget are you using? CGridView or some other?

You may want to check out some tutorials on wiki:
http://www.yiiframew...vedataprovider/
http://www.yiiframew.../?tag=cgridview
Yii extension: Captcha Extended

Greatest discoveries in 22nd century will be about the gravitation. | http://www.synet.sk | http://ipdf.sk
1

#3 User is offline   Zeke 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-February 12

Posted 01 March 2013 - 11:14 AM

View Postlubosdz, on 28 February 2013 - 04:27 PM, said:

What widget are you using? CGridView or some other?

You may want to check out some tutorials on wiki:
http://www.yiiframew...vedataprovider/
http://www.yiiframew.../?tag=cgridview


Thanks for the reply!
I'm using the CActiveForm widget for the form and there is a CJuiDialog widget (nested inside the form).

I'll take a look at those links and see if I find any helpful info.

Zeke
0

#4 User is offline   Zeke 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-February 12

Posted 01 March 2013 - 03:16 PM

Those links seem to deal with grid or list views. I am trying to load a new record into the _form view by pressing a 'Next' or 'Previous' button. I don't think ajax is an option because I really need to render the whole form page with new information.
0

#5 User is offline   waitforit 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 412
  • Joined: 09-February 11

Posted 02 March 2013 - 01:07 AM

Maybe I'm overlooking something simple but...

If each record has an ID and they are loaded like:
/site/controllerAction/bulkEdit/id

Wouldn't your next button just be id+1?

So in your bulkEdit action, get a list of all Ids you will be cycling through and generate next/last buttons with the right URL scheme.
0

#6 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 02 March 2013 - 09:51 AM

Dear Friend

The following is one simple implementation.

I hope this would serve the purpose.

Let us assume that we have model Medico.(id,name,age,sex,native)

MedicoController.php

public function actionSerialUpdate()
{   
	$criteria=new CDbCriteria();
	$count=Medico::model()->count($criteria);
	$pages=new CPagination($count);
        $pages->pageSize=1;//JUST GOING TO DISPLAY ONE RECORD.
	$pages->applyLimit($criteria);
	$model=Medico::model()->find($criteria);
	$this->performAjaxValidation($model);//JUST ENSURE THAT THIS METHOD EXISTS INSIDE YOUR CONTROLLER.
	if(isset($_POST['Medico']))
		{   
			$model=$this->loadModel($_POST['Medico']['id']);
			$model->attributes=$_POST['Medico'];
			if($model->save())
				{
					$this->render('_serialForm',array('model'=>$model,'message'=>"Successfully updated",'pages' => $pages));
					Yii::app()->end();
				}
		}
        $this->render('_serialForm', array(
			'model' => $model,
			'pages' => $pages
      ));
  }


views/medico/_serialForm.php
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'medico-form',
	'enableAjaxValidation'=>true, //ENABLED AJAX VALIDATION.
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); 
		if(isset($message)) //IF RECORD IS SUCCESSFULLY SAVED,WE ARE GOING TO DISPLAY SUCCESS MESSAGE.
			echo CHtml::tag("div",array('class'=>'flash-success'),$message);
	?>
     <!--WE ARE GOING TO HAVE A HIDDEN FIELD TO COLLECT THE PRIMARY KEY.-->
     <div class="row">
		
		<?php echo $form->hiddenField($model,'id'); ?>
		
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>64)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'age'); ?>
		<?php echo $form->textField($model,'age'); ?>
		<?php echo $form->error($model,'age'); ?>
	</div>

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

	<div class="row">
		<?php echo $form->labelEx($model,'native'); ?>
		<?php echo $form->textField($model,'native',array('size'=>60,'maxlength'=>64)); ?>
		<?php echo $form->error($model,'native'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton('Save'); ?>
	</div>

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

</div><!-- form -->

<?php $this->widget('CLinkPager', array(
      'pages' => $pages, //WE ARE GOING TO USE CLINKPAGER TO NAVIGATE ACROSS MANY RECORDS.
  )) ?>


I am using CActiveForm.
I have not tested including a dialog box inside the form.
If you are finding any difficulty in inducting a dialog box,let me know.

Regards.
0

#7 User is offline   Zeke 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-February 12

Posted 04 March 2013 - 02:04 PM

Well...I got it working. Not sure why it works the way it does but it works.

I had been trying to use a submit button or an ajax button and for what ever reason those didn't work. So I tried a link. That worked! So I made a button with the link that turned out like this:

view code:
<INPUT TYPE="button" onClick="window.location='/projectdashboard/index.php/admin/resourceProfile/getPreviousRecord?id=<?php echo $resourceProfile->id; ?>'" value="Previous">


controller code:
public function actionGetPreviousRecord() {
    $thisId = $_REQUEST['id'];
    $model = $this->loadModel($thisId);
    $record = ResourceProfile::model()->findBySql('SELECT * FROM t_resourceprofile WHERE lastName < "' . $model->lastName . '" ORDER BY lastName DESC Limit 1');
//    if ($record === null)
//      throw new CHttpException(404, 'The requested page does not exist.');
    if ($record !== null) {
      $id = $record->id;
    } else {
      $id = $thisId;
    }
    $this->render('update', array('resourceProfile' => $this->loadModel($id)));
  }


and that worked.

Maybe someone can explain why this worked and the submit buttons didn't.

Thanks,

Zeke
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