index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. 'use strict';
  2. var __assign =
  3. (this && this.__assign) ||
  4. function () {
  5. __assign =
  6. Object.assign ||
  7. function (t) {
  8. for (var s, i = 1, n = arguments.length; i < n; i++) {
  9. s = arguments[i];
  10. for (var p in s)
  11. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  12. }
  13. return t;
  14. };
  15. return __assign.apply(this, arguments);
  16. };
  17. Object.defineProperty(exports, '__esModule', { value: true });
  18. var utils_1 = require('../common/utils');
  19. var component_1 = require('../common/component');
  20. var props_1 = require('./props');
  21. component_1.VantComponent({
  22. field: true,
  23. classes: ['input-class', 'right-icon-class', 'label-class'],
  24. props: __assign(
  25. __assign(
  26. __assign(__assign({}, props_1.commonProps), props_1.inputProps),
  27. props_1.textareaProps
  28. ),
  29. {
  30. size: String,
  31. icon: String,
  32. label: String,
  33. error: Boolean,
  34. center: Boolean,
  35. isLink: Boolean,
  36. leftIcon: String,
  37. rightIcon: String,
  38. autosize: null,
  39. required: Boolean,
  40. iconClass: String,
  41. clickable: Boolean,
  42. inputAlign: String,
  43. customStyle: String,
  44. errorMessage: String,
  45. arrowDirection: String,
  46. showWordLimit: Boolean,
  47. errorMessageAlign: String,
  48. readonly: {
  49. type: Boolean,
  50. observer: 'setShowClear',
  51. },
  52. clearable: {
  53. type: Boolean,
  54. observer: 'setShowClear',
  55. },
  56. border: {
  57. type: Boolean,
  58. value: true,
  59. },
  60. titleWidth: {
  61. type: String,
  62. value: '6.2em',
  63. },
  64. }
  65. ),
  66. data: {
  67. focused: false,
  68. innerValue: '',
  69. showClear: false,
  70. },
  71. created: function () {
  72. this.value = this.data.value;
  73. this.setData({ innerValue: this.value });
  74. },
  75. methods: {
  76. onInput: function (event) {
  77. var _a = (event.detail || {}).value,
  78. value = _a === void 0 ? '' : _a;
  79. this.value = value;
  80. this.setShowClear();
  81. this.emitChange();
  82. },
  83. onFocus: function (event) {
  84. this.focused = true;
  85. this.setShowClear();
  86. this.$emit('focus', event.detail);
  87. },
  88. onBlur: function (event) {
  89. this.focused = false;
  90. this.setShowClear();
  91. this.$emit('blur', event.detail);
  92. },
  93. onClickIcon: function () {
  94. this.$emit('click-icon');
  95. },
  96. onClickInput: function (event) {
  97. this.$emit('click-input', event.detail);
  98. },
  99. onClear: function () {
  100. var _this = this;
  101. this.setData({ innerValue: '' });
  102. this.value = '';
  103. this.setShowClear();
  104. utils_1.nextTick(function () {
  105. _this.emitChange();
  106. _this.$emit('clear', '');
  107. });
  108. },
  109. onConfirm: function (event) {
  110. var _a = (event.detail || {}).value,
  111. value = _a === void 0 ? '' : _a;
  112. this.value = value;
  113. this.setShowClear();
  114. this.$emit('confirm', value);
  115. },
  116. setValue: function (value) {
  117. this.value = value;
  118. this.setShowClear();
  119. if (value === '') {
  120. this.setData({ innerValue: '' });
  121. }
  122. this.emitChange();
  123. },
  124. onLineChange: function (event) {
  125. this.$emit('linechange', event.detail);
  126. },
  127. onKeyboardHeightChange: function (event) {
  128. this.$emit('keyboardheightchange', event.detail);
  129. },
  130. emitChange: function () {
  131. var _this = this;
  132. this.setData({ value: this.value });
  133. utils_1.nextTick(function () {
  134. _this.$emit('input', _this.value);
  135. _this.$emit('change', _this.value);
  136. });
  137. },
  138. setShowClear: function () {
  139. var _a = this.data,
  140. clearable = _a.clearable,
  141. readonly = _a.readonly;
  142. var _b = this,
  143. focused = _b.focused,
  144. value = _b.value;
  145. this.setData({
  146. showClear: !!clearable && !!focused && !!value && !readonly,
  147. });
  148. },
  149. noop: function () {},
  150. },
  151. });