版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

81 wiersze
2.1 KiB

  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const HTMLInputElement_1 = __importDefault(require("../html-input-element/HTMLInputElement"));
  7. /**
  8. * Input validity state.
  9. *
  10. * @see https://developer.mozilla.org/en-US/docs/Web/API/ValidityState
  11. */
  12. class ValidityState {
  13. /**
  14. * Constructor.
  15. *
  16. * @param element Input element.
  17. */
  18. constructor(element) {
  19. this.badInput = false;
  20. this.customError = false;
  21. this.patternMismatch = false;
  22. this.rangeOverflow = false;
  23. this.rangeUnderflow = false;
  24. this.stepMismatch = false;
  25. this.element = null;
  26. this.element = element;
  27. }
  28. /**
  29. * Returns validity.
  30. *
  31. * @returns "true" if valid.
  32. */
  33. get tooLong() {
  34. if (this.element instanceof HTMLInputElement_1.default) {
  35. return this.element.maxLength && this.element.value.length > this.element.maxLength;
  36. }
  37. return false;
  38. }
  39. /**
  40. * Returns validity.
  41. *
  42. * @returns "true" if valid.
  43. */
  44. get tooShort() {
  45. if (this.element instanceof HTMLInputElement_1.default) {
  46. return this.element.minLength && this.element.value.length < this.element.minLength;
  47. }
  48. return false;
  49. }
  50. /**
  51. * Returns validity.
  52. *
  53. * @returns "true" if valid.
  54. */
  55. get typeMismatch() {
  56. return false;
  57. }
  58. /**
  59. * Returns validity.
  60. *
  61. * @returns "true" if valid.
  62. */
  63. get valueMissing() {
  64. return this.element.required && !this.element.value;
  65. }
  66. /**
  67. * Returns validity.
  68. *
  69. * @returns "true" if valid.
  70. */
  71. get valid() {
  72. for (const key of Object.keys(this)) {
  73. if (this[key]) {
  74. return false;
  75. }
  76. }
  77. return !this.tooLong && !this.tooShort && !this.typeMismatch && !this.valueMissing;
  78. }
  79. }
  80. exports.default = ValidityState;
  81. //# sourceMappingURL=ValidityState.js.map