textfield.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import _ from 'lodash'
  2. import {baseConfig} from "../base"
  3. import {text} from "../../Defaults"
  4. import {
  5. PropertyDescriptionTable,
  6. YvBase,
  7. fieldLabel,
  8. value,
  9. disabled,
  10. gravity,
  11. tooltip,
  12. metaId,
  13. width,
  14. height
  15. } from "../../PropertyDescriptionTable"
  16. import $ from 'jquery'
  17. import {PropertyDescription} from "../../PropertyDescription"
  18. export default function () {
  19. const cc = Ext.form.field.Text.prototype.constructor
  20. const {initComponent} = Ext.form.field.Text.prototype
  21. Ext.form.field.Text.override({
  22. constructor(config) {
  23. const newConfig = _.defaultsDeep({
  24. // 强制属性
  25. triggers: {
  26. clear: {
  27. weight: -1,
  28. cls: Ext.baseCSSPrefix + 'form-clear-trigger',
  29. hidden: true,
  30. handler: 'onClearClick',
  31. },
  32. }
  33. }, baseConfig(config, 'col-item'), config, text)
  34. cc.call(this, newConfig)
  35. },
  36. /**
  37. * 清空所有值
  38. */
  39. onClearClick(sender, e) {
  40. const me = this
  41. me.setValue('')
  42. },
  43. initComponent() {
  44. /**
  45. * 改变必填项之前加星号
  46. */
  47. if (this.allowBlank === false || this.validateBlank === true) {
  48. // this.beforeLabelTextTpl = [
  49. // '<span style="color:red;font-weight:bold" data-qtip="必填选项">*</span>'
  50. // ];
  51. this.afterLabelTextTpl = [
  52. '<span style="color:red;font-weight:bold" data-qtip="必填选项">*</span>'
  53. ];
  54. }
  55. const me = this
  56. this.on({
  57. change(sender, newVal) {
  58. const {hideTrigger, disabled, readOnly, hideClear} = sender
  59. if (hideTrigger || disabled || readOnly || hideClear) {
  60. // 禁用、隐藏、只读、隐藏清空状态下,不需要显示清空按钮
  61. return
  62. }
  63. const value = newVal
  64. if (value) {
  65. me.getTrigger('clear').show();
  66. me.updateLayout();
  67. } else {
  68. me.getTrigger('clear').hide();
  69. me.updateLayout();
  70. }
  71. },
  72. afterrender(sender) {
  73. if(sender.inputEl?.dom) {
  74. sender.inputEl.dom.setAttribute('spellcheck', "false");
  75. $(sender.inputEl.dom).on('click', (e)=>{
  76. sender.fireEvent('click', this, e)
  77. })
  78. }
  79. }
  80. })
  81. initComponent.call(this)
  82. }
  83. });
  84. PropertyDescriptionTable.set(
  85. 'textfield',
  86. new PropertyDescription(YvBase, {
  87. props: [
  88. fieldLabel, value, disabled,
  89. gravity, tooltip, metaId, width, height
  90. ],
  91. })
  92. )
  93. }