Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / examples / ux / SearchField.js
1 /*!
2  * Ext JS Library 3.0.3
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 Ext.ns('Ext.ux.form');\r
8 \r
9 Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {\r
10     initComponent : function(){\r
11         Ext.ux.form.SearchField.superclass.initComponent.call(this);\r
12         this.on('specialkey', function(f, e){\r
13             if(e.getKey() == e.ENTER){\r
14                 this.onTrigger2Click();\r
15             }\r
16         }, this);\r
17     },\r
18 \r
19     validationEvent:false,\r
20     validateOnBlur:false,\r
21     trigger1Class:'x-form-clear-trigger',\r
22     trigger2Class:'x-form-search-trigger',\r
23     hideTrigger1:true,\r
24     width:180,\r
25     hasSearch : false,\r
26     paramName : 'query',\r
27 \r
28     onTrigger1Click : function(){\r
29         if(this.hasSearch){\r
30             this.el.dom.value = '';\r
31             var o = {start: 0};\r
32             this.store.baseParams = this.store.baseParams || {};\r
33             this.store.baseParams[this.paramName] = '';\r
34             this.store.reload({params:o});\r
35             this.triggers[0].hide();\r
36             this.hasSearch = false;\r
37         }\r
38     },\r
39 \r
40     onTrigger2Click : function(){\r
41         var v = this.getRawValue();\r
42         if(v.length < 1){\r
43             this.onTrigger1Click();\r
44             return;\r
45         }\r
46         var o = {start: 0};\r
47         this.store.baseParams = this.store.baseParams || {};\r
48         this.store.baseParams[this.paramName] = v;\r
49         this.store.reload({params:o});\r
50         this.hasSearch = true;\r
51         this.triggers[0].show();\r
52     }\r
53 });