SearchField.js 1.4 KB

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