UNPKG

@securecall/client-component

Version:

SecureCall Core Web Component

135 lines (134 loc) 5.47 kB
import { Host, h, forceUpdate } from "@stencil/core"; import { Logger } from "../../utils/logger"; export class SecurecallRequestCurrency { fieldName; config; isValidEvent; log = new Logger('SecurecallRequestCurrency'); get value() { return this.config.value; } set value(value) { if (this.config.value !== value) { this.config.value = value; this.validateChange(); } } handleConfigChange(newConfig, oldConfig) { if (oldConfig.value !== newConfig.value) { this.value = newConfig.value; this.validateChange(); } else if (oldConfig.valid !== newConfig.valid) { this.validateChange(); } } componentWillLoad() { this.log.debug(this.fieldName + ": componentWillLoad: config", this.config); this.validateChange(); } handleChange(ev) { this.log.debug("handleChange: string change:", ev.target.value); this.value = ev.target.value; } validateChange() { const input = this.value; const num = parseFloat(input); const isValidCurrency = /^(\d+(\.\d{1,2})?)?$/.test(input); const isValid = !isNaN(num) && num !== 0 && isValidCurrency && num >= (this.config.min || 0.01) && num <= (this.config.max || 99999.99); this.log.debug(this.fieldName + ": validateChange: string:", input, "isValid:", isValid, 'config.valid', this.config.valid); if (this.config.valid !== isValid) { this.config.valid = isValid; forceUpdate(this); } this.isValidEvent.emit({ field: this.fieldName, valid: isValid, value: input }); } render() { return (h(Host, { key: 'e66b2d00594641d78171b84eeaf892cd24421a54' }, h("div", { key: '809d5891d05f4389b99b31188772a5e9467c8259', class: "field-container" }, h("label", { key: '4d600c4ab2bd2d60eb67d1e948c87acf8a377ddb', class: "custom-label", htmlFor: this.fieldName }, this.config.label, ":"), h("input", { key: '156e37b7333b64567ae0b9d75b19ef0275af633e', type: "text", class: "custom-input", id: this.fieldName, placeholder: this.config.placeholder || this.config.label, value: this.value, disabled: this.config.readOnly, onInput: (ev) => this.handleChange(ev) }), h("div", { key: '8d027ba0bc68e9ad3fb6d8056520205b2e149b5d', class: this.config.valid ? 'field-valid' : 'field-invalid' })))); } static get is() { return "securecall-request-currency"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["securecall-request-currency.css"] }; } static get styleUrls() { return { "$": ["securecall-request-currency.css"] }; } static get properties() { return { "fieldName": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "reflect": false, "attribute": "field-name" }, "config": { "type": "unknown", "mutable": true, "complexType": { "original": "IRequestField", "resolved": "{ hidden?: boolean; label?: string; value?: string; max?: number; min?: number; placeholder?: string; readOnly?: boolean; order?: number; component?: string; valid?: boolean; possibleValues?: Record<string, string>; mapping?: string; externalMapping?: string; active?: boolean; hideRelatedFields?: Record<string, object>; secure?: boolean; optional?: boolean; }", "references": { "IRequestField": { "location": "import", "path": "../../interfaces/configuration", "id": "src/interfaces/configuration.ts::IRequestField" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false } }; } static get events() { return [{ "method": "isValidEvent", "name": "isValidEvent", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "" }, "complexType": { "original": "{ field: string; valid: boolean, value: string }", "resolved": "{ field: string; valid: boolean; value: string; }", "references": {} } }]; } static get watchers() { return [{ "propName": "config", "methodName": "handleConfigChange" }]; } } //# sourceMappingURL=securecall-request-currency.js.map