Yii Framework Forum: Avoiding form submission on enter in a CGridView filter field. - Yii Framework Forum

Jump to content

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

Avoiding form submission on enter in a CGridView filter field. Patch incliuded. Rate Topic: -----

#1 User is offline   MetaYii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 379
  • Joined: 07-October 08
  • Location:The Matrix

Posted 25 August 2011 - 04:12 PM

The problem is detailed here:

http://www.yiiframew...rid#entry110230

The patch to solve this problem is:

--- assets/gridview/jquery.yiigridview.js   	(revisión: 332)
+++ assets/gridview/jquery.yiigridview.js   	(copia de trabajo)
@@ -41,6 +41,18 @@
                    	}
 
                    	var inputSelector='#'+id+' .'+settings.filterClass+' input, '+'#'+id+' .'+settings.filterClass+' select';
+                       		$('body').undelegate(inputSelector, 'keydown').delegate(inputSelector, 'keydown', function(k){
+       		if (k.keyCode == 13) {
+               		var data = $(inputSelector).serialize();
+               		if(settings.pageVar!==undefined)
+       		data += '&'+settings.pageVar+'=1';
+               		$.fn.yiigridview.update(id, {data: data});
+               		return false;
+       		}
+       		else {
+               		return k;
+       		}
+                       		});
                    	$('body').undelegate(inputSelector, 'change').delegate(inputSelector, 'change', function(){
                            	var data = $(inputSelector).serialize();
                            	if(settings.pageVar!==undefined)



So, if you have a CGridView inside a CForm or CActiveForm, the form won't be submitted when you press enter in a filter text field, but the search will be performed.

Please consider including it the official source code.
Ah! on-off, simplement!
3

#2 User is offline   MetaYii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 379
  • Joined: 07-October 08
  • Location:The Matrix

Posted 25 August 2011 - 04:19 PM

Opened an issue for this here:

http://code.google.c.../detail?id=2771
Ah! on-off, simplement!
0

#3 User is offline   Greg Molnar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 17-January 11

Posted 05 September 2011 - 09:36 AM

there is a typo:
 $.fn.yiigridview.update(id, {data: data});

should be $.fn.yiiGridView.update(id, {data: data});

other than that it is a nice fix. thank you.
0

#4 User is offline   jcsmesquita 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 27-July 11

Posted 04 December 2011 - 03:04 AM

This is exactly what I was looking for!

Thanks :)
0

#5 User is offline   Malcolm Y. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 27-October 11

Posted 08 January 2012 - 04:03 AM

i encounter a similar problem when using cactiveform with just one textinput. Upon pressing enter form submits ahead.
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