index.js 4.7 KB

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