项目原始demo,不改动
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
Tento repozitář je archivovaný. Můžete prohlížet soubory, klonovat, ale nemůžete nahrávat a vytvářet nové úkoly a požadavky na natažení.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _mixins = _interopRequireDefault(require("../../util/mixins"));
  7. var _bindsAttrs = _interopRequireDefault(require("../../mixins/binds-attrs"));
  8. var _registrable = require("../../mixins/registrable");
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  11. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  12. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  13. /* @vue/component */
  14. var _default = (0, _mixins.default)(_bindsAttrs.default, (0, _registrable.provide)('form')
  15. /* @vue/component */
  16. ).extend({
  17. name: 'v-form',
  18. inheritAttrs: false,
  19. props: {
  20. lazyValidation: Boolean,
  21. value: Boolean
  22. },
  23. data: function data() {
  24. return {
  25. inputs: [],
  26. watchers: [],
  27. errorBag: {}
  28. };
  29. },
  30. watch: {
  31. errorBag: {
  32. handler: function handler(val) {
  33. var errors = Object.values(val).includes(true);
  34. this.$emit('input', !errors);
  35. },
  36. deep: true,
  37. immediate: true
  38. }
  39. },
  40. methods: {
  41. watchInput: function watchInput(input) {
  42. var _this = this;
  43. var watcher = function watcher(input) {
  44. return input.$watch('hasError', function (val) {
  45. _this.$set(_this.errorBag, input._uid, val);
  46. }, {
  47. immediate: true
  48. });
  49. };
  50. var watchers = {
  51. _uid: input._uid,
  52. valid: function valid() {},
  53. shouldValidate: function shouldValidate() {}
  54. };
  55. if (this.lazyValidation) {
  56. // Only start watching inputs if we need to
  57. watchers.shouldValidate = input.$watch('shouldValidate', function (val) {
  58. if (!val) return; // Only watch if we're not already doing it
  59. if (_this.errorBag.hasOwnProperty(input._uid)) return;
  60. watchers.valid = watcher(input);
  61. });
  62. } else {
  63. watchers.valid = watcher(input);
  64. }
  65. return watchers;
  66. },
  67. /** @public */
  68. validate: function validate() {
  69. return this.inputs.filter(function (input) {
  70. return !input.validate(true);
  71. }).length === 0;
  72. },
  73. /** @public */
  74. reset: function reset() {
  75. this.inputs.forEach(function (input) {
  76. return input.reset();
  77. });
  78. this.resetErrorBag();
  79. },
  80. resetErrorBag: function resetErrorBag() {
  81. var _this2 = this;
  82. if (this.lazyValidation) {
  83. // Account for timeout in validatable
  84. setTimeout(function () {
  85. _this2.errorBag = {};
  86. }, 0);
  87. }
  88. },
  89. /** @public */
  90. resetValidation: function resetValidation() {
  91. this.inputs.forEach(function (input) {
  92. return input.resetValidation();
  93. });
  94. this.resetErrorBag();
  95. },
  96. register: function register(input) {
  97. this.inputs.push(input);
  98. this.watchers.push(this.watchInput(input));
  99. },
  100. unregister: function unregister(input) {
  101. var found = this.inputs.find(function (i) {
  102. return i._uid === input._uid;
  103. });
  104. if (!found) return;
  105. var unwatch = this.watchers.find(function (i) {
  106. return i._uid === found._uid;
  107. });
  108. if (unwatch) {
  109. unwatch.valid();
  110. unwatch.shouldValidate();
  111. }
  112. this.watchers = this.watchers.filter(function (i) {
  113. return i._uid !== found._uid;
  114. });
  115. this.inputs = this.inputs.filter(function (i) {
  116. return i._uid !== found._uid;
  117. });
  118. this.$delete(this.errorBag, found._uid);
  119. }
  120. },
  121. render: function render(h) {
  122. var _this3 = this;
  123. return h('form', {
  124. staticClass: 'v-form',
  125. attrs: _objectSpread({
  126. novalidate: true
  127. }, this.attrs$),
  128. on: {
  129. submit: function submit(e) {
  130. return _this3.$emit('submit', e);
  131. }
  132. }
  133. }, this.$slots.default);
  134. }
  135. });
  136. exports.default = _default;
  137. //# sourceMappingURL=VForm.js.map