UNPKG

@mokmaard/dar-component-object

Version:
125 lines 4.01 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Field = void 0; const Input_1 = require("../core/Input"); const enum_1 = require("../enum"); const FieldConditions_1 = require("./FieldConditions"); const class_transformer_1 = require("class-transformer"); const class_validator_1 = require("class-validator"); require("reflect-metadata"); class Field extends Input_1.Input { required = true; isUseConditions = false; type = enum_1.FieldType.TEXT; conditions = new FieldConditions_1.FieldConditions(); isUseMultipleValues = false; placeholder = null; maximumValueSize = 1; setMaximumValueSize(size) { if (!this.isUseMultipleValues) { console.warn("Values type is not multiple."); return this; } if (size <= 1) { console.error("Maximum size should not be less than 0"); return this; } this.maximumValueSize = size; return this; } setIsUseMultipleValues(isUse) { this.isUseMultipleValues = isUse; return this; } setRequired(required) { this.required = required; return this; } setType(type) { this.type = type; return this; } setValue(value, index = 0) { if (!this.values) { this.values = []; } this.values[index] = value; return this; } setValues(value) { this.values = value; return this; } addValue(value) { if (!this.values) { this.values = []; } // if not multiple, set single value and return if (!this.isUseMultipleValues) { console.warn("Values type is not multiple. set single value instead."); this.values = [value]; return this; } this.values.push(value); return this; } deleteValue(index) { if (this.values) { this.values.splice(index, 1); } return this; } setPlaceholder(placeholder) { this.placeholder = placeholder; return this; } setIsUseConditions(isUse) { this.isUseConditions = isUse; return this; } setConditions(conditions) { this.conditions = conditions; return this; } getType() { return this.type; } setFieldConditions(conditions) { this.conditions = conditions; return this; } } exports.Field = Field; __decorate([ (0, class_validator_1.IsBoolean)() ], Field.prototype, "required", void 0); __decorate([ (0, class_validator_1.IsBoolean)() ], Field.prototype, "isUseConditions", void 0); __decorate([ (0, class_validator_1.IsEnum)(enum_1.FieldType) ], Field.prototype, "type", void 0); __decorate([ (0, class_transformer_1.Type)(() => FieldConditions_1.FieldConditions), (0, class_validator_1.ValidateNested)() ], Field.prototype, "conditions", void 0); __decorate([ (0, class_validator_1.IsArray)() ], Field.prototype, "values", void 0); __decorate([ (0, class_validator_1.IsBoolean)() ], Field.prototype, "isUseMultipleValues", void 0); __decorate([ (0, class_validator_1.IsOptional)() ], Field.prototype, "placeholder", void 0); __decorate([ (0, class_validator_1.IsNumber)(), (0, class_validator_1.Min)(1) ], Field.prototype, "maximumValueSize", void 0); //# sourceMappingURL=Field.js.map