@react-form-fields/material-ui
Version:
Material UI Form Fields
34 lines • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ValidationContext_1 = require("@react-form-fields/core/ValidationContext");
var React = require("react");
var FormValidation = React.memo(React.forwardRef(function (props, ref) {
var validationContext = React.useRef(null);
React.useImperativeHandle(ref, function () { return ({
isValid: function (formSubmitted) {
if (formSubmitted === void 0) { formSubmitted = true; }
return validationContext.current.isValid(formSubmitted);
},
reset: function () { return validationContext.current.reset(); }
}); }, []);
var onSubmit = React.useCallback(function (e) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var isValid;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
e && e.preventDefault && e.preventDefault();
e && e.stopPropagation && e.stopPropagation();
return [4 /*yield*/, validationContext.current.isValid(true)];
case 1:
isValid = _a.sent();
props.onSubmit(isValid);
return [2 /*return*/];
}
});
}); }, [props]);
return (React.createElement("form", { noValidate: true, onSubmit: onSubmit, className: props.className },
React.createElement(ValidationContext_1.default, { ref: validationContext }, props.children)));
}));
exports.default = FormValidation;
//# sourceMappingURL=FormValidation.js.map