Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / examples / ux / SearchField.js
diff --git a/examples/ux/SearchField.js b/examples/ux/SearchField.js
new file mode 100644 (file)
index 0000000..0d58e94
--- /dev/null
@@ -0,0 +1,53 @@
+/*!
+ * Ext JS Library 3.0.0
+ * Copyright(c) 2006-2009 Ext JS, LLC
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+Ext.ns('Ext.ux.form');\r
+\r
+Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {\r
+    initComponent : function(){\r
+        Ext.ux.form.SearchField.superclass.initComponent.call(this);\r
+        this.on('specialkey', function(f, e){\r
+            if(e.getKey() == e.ENTER){\r
+                this.onTrigger2Click();\r
+            }\r
+        }, this);\r
+    },\r
+\r
+    validationEvent:false,\r
+    validateOnBlur:false,\r
+    trigger1Class:'x-form-clear-trigger',\r
+    trigger2Class:'x-form-search-trigger',\r
+    hideTrigger1:true,\r
+    width:180,\r
+    hasSearch : false,\r
+    paramName : 'query',\r
+\r
+    onTrigger1Click : function(){\r
+        if(this.hasSearch){\r
+            this.el.dom.value = '';\r
+            var o = {start: 0};\r
+            this.store.baseParams = this.store.baseParams || {};\r
+            this.store.baseParams[this.paramName] = '';\r
+            this.store.reload({params:o});\r
+            this.triggers[0].hide();\r
+            this.hasSearch = false;\r
+        }\r
+    },\r
+\r
+    onTrigger2Click : function(){\r
+        var v = this.getRawValue();\r
+        if(v.length < 1){\r
+            this.onTrigger1Click();\r
+            return;\r
+        }\r
+        var o = {start: 0};\r
+        this.store.baseParams = this.store.baseParams || {};\r
+        this.store.baseParams[this.paramName] = v;\r
+        this.store.reload({params:o});\r
+        this.hasSearch = true;\r
+        this.triggers[0].show();\r
+    }\r
+});
\ No newline at end of file