textfield.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import _ from 'lodash'
  2. import {baseConfig} from "../base";
  3. import {text} from "../../Defaults";
  4. export default function () {
  5. const cc = Ext.form.field.Text.prototype.constructor
  6. const {initComponent} = Ext.form.field.Text.prototype
  7. Ext.form.field.Text.override({
  8. constructor(config) {
  9. const newConfig = _.defaultsDeep({
  10. // 强制属性
  11. triggers: {
  12. clear: {
  13. weight: -1,
  14. cls: Ext.baseCSSPrefix + 'form-clear-trigger',
  15. hidden: true,
  16. handler: 'onClearClick',
  17. },
  18. }
  19. }, baseConfig(config, 'col-item'), config, text)
  20. cc.call(this, newConfig)
  21. },
  22. /**
  23. * 清空所有值
  24. */
  25. onClearClick(sender, e) {
  26. const me = this
  27. me.setValue('')
  28. },
  29. initComponent() {
  30. /**
  31. * 改变必填项之前加星号
  32. */
  33. if (this.allowBlank === false || this.validateBlank === true) {
  34. this.beforeLabelTextTpl = [
  35. '<span style="color:red;font-weight:bold" data-qtip="必填选项">*</span>'
  36. ];
  37. }
  38. const me = this
  39. this.on({
  40. change(sender, newVal) {
  41. const {hideTrigger, disabled, readonly} = sender
  42. if (hideTrigger || disabled || readonly) {
  43. // 禁用、隐藏、只读状态下,不需要显示清空按钮
  44. return
  45. }
  46. const value = newVal
  47. if (value) {
  48. me.getTrigger('clear').show();
  49. me.updateLayout();
  50. } else {
  51. me.getTrigger('clear').hide();
  52. me.updateLayout();
  53. }
  54. }
  55. })
  56. initComponent.call(this)
  57. }
  58. });
  59. }