Avoiding form submission on enter in a CGridView filter field.

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.

Opened an issue for this here:

http://code.google.com/p/yii/issues/detail?id=2771

there is a typo:

[html] $.fn.yiigridview.update(id, {data: data});[/html]

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

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

This is exactly what I was looking for!

Thanks :)

i encounter a similar problem when using cactiveform with just one textinput. Upon pressing enter form submits ahead.