Yii Framework Forum: How to refresh the view on a button click - Yii Framework Forum

Jump to content

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

How to refresh the view on a button click Rate Topic: -----

#1 User is offline   Yiaan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 01-March 12
  • Location:France

Posted 14 March 2012 - 10:15 AM

Hi,
I've tried coding the options of CHtml::button in many many different ways, so that when I click on it, the current view would be refreshed, but I couldn't succeed, so I'm asking for some help...
I'm using Yii 1.1.5.

Here is the last code I've tried with no success :
<?php echo CHtml::button('RĂ©initialiser', array('clientChange', array('click' => CController->refresh()))); ?>


Thanks in advance...
0

#2 User is offline   R.K. 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 117
  • Joined: 20-September 10

Posted 14 March 2012 - 10:35 AM

you can load content via ajax, or you can make refresh whole page. check window.location.reload
0

#3 User is offline   Yiaan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 01-March 12
  • Location:France

Posted 14 March 2012 - 10:45 AM

Actually I wanted to use the Yii refresh function because the effect of this method call is the same as user pressing the refresh button on the browser (without post data).

With window.location.reload the post data is sent along...
0

#4 User is offline   tof 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 07-October 08
  • Location:Sophia Antipolis - French Riviera

Posted 14 March 2012 - 11:10 AM

Hello 'cher compatriote' Posted Image

You can't call a serverside method directly from clientside... the 'click' action on a button is a javascript client side event, and won't raise a server side one (except in case of form post)

The easier for me is to put a link (not a button), with the current url (Yii::app()->getRequest()->getUrl()), or, if you really want a button, use a javascript onClick event to set window.location to the current url
echo CHtml::htmlButton ('Refresh', array('onClick'=>'window.location="'.Yii::app()->getRequest()->getUrl().'"'));

0

#5 User is offline   Yiaan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 01-March 12
  • Location:France

Posted 14 March 2012 - 11:40 AM

Hi 'voisin' (I'm in Nice ;) ),

well thanks for your answer, it works. I can even replace htmlButton with Button, it works as well. Actually, according to the Yii documentation, you can use clientChange with Button, and with clientChange you can use javascript events. That's what I was trying to do...
0

#6 User is offline   tof 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 07-October 08
  • Location:Sophia Antipolis - French Riviera

Posted 14 March 2012 - 11:53 AM

No, clientchange can't be use to attach event handler.
Look at its documentation, and the source code... With theses options, you can change the submit url, or add a "confirm", or change the return value of the default 'onclick' event, but you can't change the event itself.
You can only do that with classic 'onclick' html attribute, or by attaching your own event handler with some jQuery.

I used htmlButton instead of button, because the former will render a <button>, which is, imho, better than <input type="submit"> when there's no form submission...
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