react-form-with-constraints
Version:
Simple form validation for React
43 lines (42 loc) • 1.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InputElement = exports.isHTMLInput = exports.IValidityState = void 0;
class IValidityState {
constructor(validity) {
this.badInput = validity.badInput;
this.customError = validity.customError;
this.patternMismatch = validity.patternMismatch;
this.rangeOverflow = validity.rangeOverflow;
this.rangeUnderflow = validity.rangeUnderflow;
this.stepMismatch = validity.stepMismatch;
this.tooLong = validity.tooLong;
this.tooShort = validity.tooShort;
this.typeMismatch = validity.typeMismatch;
this.valid = validity.valid;
this.valueMissing = validity.valueMissing;
}
}
exports.IValidityState = IValidityState;
function isHTMLInput(input) {
return input.props === undefined;
}
exports.isHTMLInput = isHTMLInput;
class InputElement {
constructor(input) {
if (isHTMLInput(input)) {
this.name = input.name;
this.type = input.type;
this.value = input.value;
this.validity = new IValidityState(input.validity);
this.validationMessage = input.validationMessage;
}
else {
this.name = input.props.name;
this.type = undefined;
this.value = input.props.value;
this.validity = undefined;
this.validationMessage = undefined;
}
}
}
exports.InputElement = InputElement;