ComboBox.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. Ext.define("school.override.form.field.ComboBox", {
  2. override: "Ext.form.field.ComboBox",
  3. clearable: false,
  4. config: {
  5. triggers: {
  6. clear: {
  7. weight: -1,
  8. cls: 'fa-times',
  9. hidden: true,
  10. lazyVisible: true,
  11. onFieldFocus: function() {
  12. var field = this.field;
  13. if(!field.readOnly && field.clearable) {
  14. this.setHidden(false);
  15. }
  16. },
  17. onFieldBlur: function() {
  18. var field = this.field;
  19. if(!field.readOnly && field.clearable) {
  20. this.setHidden(true);
  21. }
  22. },
  23. handler: function() {
  24. if(!this.readOnly && this.clearable) {
  25. this.setValue(null)
  26. this.triggers.clear.setHidden(true)
  27. this.fireEvent('clear', this);
  28. }
  29. }
  30. },
  31. picker: {
  32. handler: 'onTriggerClick',
  33. scope: 'this',
  34. focusOnMousedown: true
  35. }
  36. }
  37. },
  38. setReadOnly: function(readOnly) {
  39. var me = this,
  40. triggers = me.getTriggers(),
  41. hideTriggers = me.getHideTrigger(),
  42. oVisible = {},
  43. trigger,
  44. id;
  45. readOnly = !!readOnly;
  46. if (triggers) {
  47. for (id in triggers) {
  48. oVisible[id] = triggers[id].isVisible();
  49. }
  50. }
  51. me.callParent([readOnly]);
  52. if (me.rendered) {
  53. me.setReadOnlyAttr(readOnly || !me.editable);
  54. }
  55. if (triggers) {
  56. for (id in triggers) {
  57. trigger = triggers[id];
  58. /**
  59. * if trigger's 'lazyVisible' is true,this trigger's 'visible' will not controlled beed 'setReadOnly'
  60. */
  61. if(trigger.lazyVisible) {
  62. trigger.setVisible(oVisible[id]);
  63. continue;
  64. }
  65. /*
  66. * Controlled trigger visibility state is only managed fully when 'hideOnReadOnly' is falsy.
  67. * Truth table:
  68. * - If the trigger is configured/defaulted as 'hideOnReadOnly : true', it's readOnly-visibility
  69. * is determined solely by readOnly state of the Field.
  70. * - If 'hideOnReadOnly : false/undefined', the Fields.{link #hideTrigger hideTrigger} is honored.
  71. */
  72. if (trigger.hideOnReadOnly === true || (trigger.hideOnReadOnly !== false && !hideTriggers)) {
  73. trigger.setVisible(!readOnly);
  74. }
  75. }
  76. }
  77. },
  78. });