UNPKG

armisa-models

Version:
50 lines (49 loc) 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidatingControl = void 0; const BaseSelfControl_1 = require("../SelfModels/BaseSelfControl"); class ValidatieValuesClass { constructor(propertyName, controls) { this.propertyName = propertyName; this.controls = controls; } } class ValidatingControl { constructor(pageData) { this.pageData = pageData; this.controls = []; this.removeControl = (property) => { this.controls = this.controls.filter((i) => i.propertyName !== property.propertyName); }; this.removeAllControls = () => { this.controls = []; }; this.validateForm = (mainState) => { // const props = Array.from(new Set(this.controls.filter(i => !i.disabled).map(i => i.propertyName))); if (!this.controls || this.controls.length === 0) { return 0; } let isValid = 0; this.pageData.TouchingControl.setAllTouched(); for (const property of this.controls) { const selfControl = mainState[property.propertyName]; if (selfControl instanceof BaseSelfControl_1.BaseSelfControl) { selfControl.validate(); if (typeof selfControl.validation !== 'boolean') { isValid++; } } } this.pageData.Eventing.trigger('form.change'); return isValid; }; } addControl(property) { const control = this.controls.find((i) => i.propertyName === property.propertyName); if (control) { return; } this.controls.push(new ValidatieValuesClass(property.propertyName, property.controlRef.current)); } } exports.ValidatingControl = ValidatingControl;