Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / examples / docs / source / SearchField.html
1 <html>
2 <head>
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
4   <title>The source code</title>
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 </head>
8 <body  onload="prettyPrint();">
9     <pre class="prettyprint lang-js">/*!
10  * Ext JS Library 3.3.1
11  * Copyright(c) 2006-2010 Sencha Inc.
12  * licensing@sencha.com
13  * http://www.sencha.com/license
14  */
15 Ext.ns('Ext.ux.form');
16
17 Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
18     initComponent : function(){
19         Ext.ux.form.SearchField.superclass.initComponent.call(this);
20         this.on('specialkey', function(f, e){
21             if(e.getKey() == e.ENTER){
22                 this.onTrigger2Click();
23             }
24         }, this);
25     },
26
27     validationEvent:false,
28     validateOnBlur:false,
29     trigger1Class:'x-form-clear-trigger',
30     trigger2Class:'x-form-search-trigger',
31     hideTrigger1:true,
32     width:180,
33     hasSearch : false,
34     paramName : 'query',
35
36     onTrigger1Click : function(){
37         if(this.hasSearch){
38             this.el.dom.value = '';
39             var o = {start: 0};
40             this.store.baseParams = this.store.baseParams || {};
41             this.store.baseParams[this.paramName] = '';
42             this.store.reload({params:o});
43             this.triggers[0].hide();
44             this.hasSearch = false;
45         }
46     },
47
48     onTrigger2Click : function(){
49         var v = this.getRawValue();
50         if(v.length < 1){
51             this.onTrigger1Click();
52             return;
53         }
54         var o = {start: 0};
55         this.store.baseParams = this.store.baseParams || {};
56         this.store.baseParams[this.paramName] = v;
57         this.store.reload({params:o});
58         this.hasSearch = true;
59         this.triggers[0].show();
60     }
61 });</pre>    
62 </body>
63 </html>