index.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. 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. } }),
  39. data: {
  40. focused: false,
  41. innerValue: '',
  42. showClear: false,
  43. },
  44. created: function () {
  45. this.value = this.data.value;
  46. this.setData({ innerValue: this.value });
  47. },
  48. methods: {
  49. onInput: function (event) {
  50. var _a = (event.detail || {}).value, value = _a === void 0 ? '' : _a;
  51. this.value = value;
  52. this.setShowClear();
  53. this.emitChange();
  54. },
  55. onFocus: function (event) {
  56. this.focused = true;
  57. this.setShowClear();
  58. this.$emit('focus', event.detail);
  59. },
  60. onBlur: function (event) {
  61. this.focused = false;
  62. this.setShowClear();
  63. this.$emit('blur', event.detail);
  64. },
  65. onClickIcon: function () {
  66. this.$emit('click-icon');
  67. },
  68. onClickInput: function (event) {
  69. this.$emit('click-input', event.detail);
  70. },
  71. onClear: function () {
  72. var _this = this;
  73. this.setData({ innerValue: '' });
  74. this.value = '';
  75. this.setShowClear();
  76. utils_1.nextTick(function () {
  77. _this.emitChange();
  78. _this.$emit('clear', '');
  79. });
  80. },
  81. onConfirm: function (event) {
  82. var _a = (event.detail || {}).value, value = _a === void 0 ? '' : _a;
  83. this.value = value;
  84. this.setShowClear();
  85. this.$emit('confirm', value);
  86. },
  87. setValue: function (value) {
  88. this.value = value;
  89. this.setShowClear();
  90. if (value === '') {
  91. this.setData({ innerValue: '' });
  92. }
  93. this.emitChange();
  94. },
  95. onLineChange: function (event) {
  96. this.$emit('linechange', event.detail);
  97. },
  98. onKeyboardHeightChange: function (event) {
  99. this.$emit('keyboardheightchange', event.detail);
  100. },
  101. emitChange: function () {
  102. var _this = this;
  103. this.setData({ value: this.value });
  104. utils_1.nextTick(function () {
  105. _this.$emit('input', _this.value);
  106. _this.$emit('change', _this.value);
  107. });
  108. },
  109. setShowClear: function () {
  110. var _a = this.data, clearable = _a.clearable, readonly = _a.readonly, clearTrigger = _a.clearTrigger;
  111. var _b = this, focused = _b.focused, value = _b.value;
  112. var showClear = false;
  113. if (clearable && !readonly) {
  114. var hasValue = !!value;
  115. var trigger = clearTrigger === 'always' || (clearTrigger === 'focus' && focused);
  116. showClear = hasValue && trigger;
  117. }
  118. this.setData({ showClear: showClear });
  119. },
  120. noop: function () { },
  121. },
  122. });