index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. component_1.VantComponent({
  5. field: true,
  6. classes: ['input-class', 'right-icon-class'],
  7. props: {
  8. size: String,
  9. icon: String,
  10. label: String,
  11. error: Boolean,
  12. fixed: Boolean,
  13. focus: Boolean,
  14. center: Boolean,
  15. isLink: Boolean,
  16. leftIcon: String,
  17. rightIcon: String,
  18. disabled: Boolean,
  19. autosize: Boolean,
  20. readonly: Boolean,
  21. required: Boolean,
  22. password: Boolean,
  23. iconClass: String,
  24. clearable: Boolean,
  25. inputAlign: String,
  26. customClass: String,
  27. customStyle: String,
  28. confirmType: String,
  29. confirmHold: Boolean,
  30. errorMessage: String,
  31. placeholder: String,
  32. placeholderStyle: String,
  33. errorMessageAlign: String,
  34. showConfirmBar: {
  35. type: Boolean,
  36. value: true
  37. },
  38. adjustPosition: {
  39. type: Boolean,
  40. value: true
  41. },
  42. cursorSpacing: {
  43. type: Number,
  44. value: 50
  45. },
  46. maxlength: {
  47. type: Number,
  48. value: -1
  49. },
  50. type: {
  51. type: String,
  52. value: 'text'
  53. },
  54. border: {
  55. type: Boolean,
  56. value: true
  57. },
  58. titleWidth: {
  59. type: String,
  60. value: '90px'
  61. }
  62. },
  63. data: {
  64. showClear: false
  65. },
  66. beforeCreate: function () {
  67. this.focused = false;
  68. },
  69. methods: {
  70. onInput: function (event) {
  71. var _this = this;
  72. var _a = (event.detail || {}).value, value = _a === void 0 ? '' : _a;
  73. this.set({
  74. value: value,
  75. showClear: this.getShowClear(value)
  76. }, function () {
  77. _this.emitChange(value);
  78. });
  79. },
  80. onFocus: function (event) {
  81. var _a = event.detail || {}, _b = _a.value, value = _b === void 0 ? '' : _b, _c = _a.height, height = _c === void 0 ? 0 : _c;
  82. this.$emit('focus', { value: value, height: height });
  83. this.focused = true;
  84. this.blurFromClear = false;
  85. this.set({
  86. showClear: this.getShowClear()
  87. });
  88. },
  89. onBlur: function (event) {
  90. var _this = this;
  91. var _a = event.detail || {}, _b = _a.value, value = _b === void 0 ? '' : _b, _c = _a.cursor, cursor = _c === void 0 ? 0 : _c;
  92. this.$emit('blur', { value: value, cursor: cursor });
  93. this.focused = false;
  94. var showClear = this.getShowClear();
  95. if (this.data.value === value) {
  96. this.set({
  97. showClear: showClear
  98. });
  99. }
  100. else if (!this.blurFromClear) {
  101. // fix: the handwritten keyboard does not trigger input change
  102. this.set({
  103. value: value,
  104. showClear: showClear
  105. }, function () {
  106. _this.emitChange(value);
  107. });
  108. }
  109. },
  110. onClickIcon: function () {
  111. this.$emit('click-icon');
  112. },
  113. getShowClear: function (value) {
  114. value = value === undefined ? this.data.value : value;
  115. return (this.data.clearable && this.focused && value && !this.data.readonly);
  116. },
  117. onClear: function () {
  118. var _this = this;
  119. this.blurFromClear = true;
  120. this.set({
  121. value: '',
  122. showClear: this.getShowClear('')
  123. }, function () {
  124. _this.emitChange('');
  125. _this.$emit('clear', '');
  126. });
  127. },
  128. onConfirm: function () {
  129. this.$emit('confirm', this.data.value);
  130. },
  131. emitChange: function (value) {
  132. this.$emit('input', value);
  133. this.$emit('change', value);
  134. }
  135. }
  136. });