Yii Framework Forum: Reset button reloading page - Yii Framework Forum

Jump to content

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

Reset button reloading page (or can I have two submit buttons in one form) Rate Topic: -----

#1 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,181
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 27 January 2011 - 09:27 AM

Orignal Yii demo app does not contains Reset button in Advanced Search form placed above any CGridView. I have developed one (discussed in this thread) and also provided a version that clears not CGridView header filter fields, but form fields instead (here).

The idea was to have Reset button working the same as Submit button - i.e. clearing all fields and updating CGridView via AJAX request without page reload (as in standard forms). In particular the code was:

$('#form-reset-button').click(function()
{
    	$('#search-form form input, #search-form form select').each(function(i, o)
    	{
            	if (($(o).attr('type') != 'submit') && ($(o).attr('type') != 'reset')) $(o).val('');
    	});

    	$.fn.yiiGridView.update('pacjenci-grid', {data: $('#search-form form').serialize()});

    	return false;
});

Now, what I want is to have just simple, pure Reset button which clears all the fields and then reloads the whole page (required to update CGridView but not via AJAX call this time, only in normal form process operation).

For this purpose, I commented out gridview update call and return false in above code, but that does not forces reset button to reload whole page. I managed to do so, by changing reset button to another submit button.

Now, it works as I wanted (clears all fields with above code and reload whole page), but the question is, if according to standards and coding practice, can I have two submit buttons in one form?
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,317
  • Joined: 12-October 09
  • Location:Croatia

Posted 27 January 2011 - 09:32 AM

Why not... it's OK to have more submit buttons...

One idea for resetting CGridView would be to have a button or link with the original url... like "model/admin"
Find more about me.... btw. Do you know your WAN IP?
1

#3 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,181
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 27 January 2011 - 09:36 AM

Hm...

View Postmdomba, on 27 January 2011 - 09:32 AM, said:

One idea for resetting CGridView would be to have a button or link with the original url... like "model/admin"


$('#form-reset-button').click(function()
{
    	location.href = '".$this->createUrl('pacjenci/index')."'
});

Brilliant! :]
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#4 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 27 January 2011 - 10:09 AM

Your code looks ok, I'd just change:

        $.fn.yiiGridView.update('pacjenci-grid', {data: '');




If you cleaned the fields, what for to collect data once more?
0

#5 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,181
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 27 January 2011 - 10:23 AM

View Postzaccaria, on 27 January 2011 - 10:09 AM, said:

If you cleaned the fields, what for to collect data once more?

This line of code is commented-out (not deleted - for future references, i.e. my boss likes to change his mind often! :]). In current version it is not being executed, as there is no need to update CGridView via AJAX. It is being updated via standard request.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#6 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,317
  • Joined: 12-October 09
  • Location:Croatia

Posted 27 January 2011 - 11:20 AM

View PostTrejder, on 27 January 2011 - 09:36 AM, said:

$('#form-reset-button').click(function()
{
    	location.href = '".$this->createUrl('pacjenci/index')."'
});



Actualy you don't need to use javascript at all... just set the url of the button from PHP
Find more about me.... btw. Do you know your WAN IP?
0

#7 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,317
  • Joined: 12-October 09
  • Location:Croatia

Posted 27 January 2011 - 11:22 AM

View Postzaccaria, on 27 January 2011 - 10:09 AM, said:

Your code looks ok, I'd just change:

        $.fn.yiiGridView.update('pacjenci-grid', {data: '');




If you cleaned the fields, what for to collect data once more?


It's because you need to send all filter variables set to empty... if you just send '' it would not empty the CGridView filter
Find more about me.... btw. Do you know your WAN IP?
0

#8 User is offline   Mahdi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 127
  • Joined: 23-August 10
  • Location:Tunisia

Posted 28 January 2011 - 04:25 AM

View Postzaccaria, on 27 January 2011 - 10:09 AM, said:

        $.fn.yiiGridView.update('pacjenci-grid', {data: '');



missing } after property list :

$.fn.yiiGridView.update('pacjenci-grid', {data: ''});

0

#9 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,181
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 29 January 2011 - 10:46 AM

View Postmdomba, on 27 January 2011 - 11:20 AM, said:

Actualy you don't need to use javascript at all... just set the url of the button from PHP

Yes! I know that. But it is not the only line of the code in this function. There are several more commented-out (as I just said - my boss likes to change his mind sometimes too often), I just didn't paste them, not to waste space.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#10 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,181
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 29 January 2011 - 10:47 AM

View PostMahdi, on 28 January 2011 - 04:25 AM, said:

missing } after property list :

Thanks, Mahdi! :]
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

Share this topic:


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

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users