/* * Copyright (c) 2010, 2026 BSI Business Systems Integration AG * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 */ import { aria, BasicField, DesktopNotification, EnumObject, fields, InitModelOf, InputFieldKeyStrokeContext, JQueryWheelEvent, MaxLengthHandler, objects, scout, Status, StringFieldCtrlEnterKeyStroke, StringFieldEnterKeyStroke, StringFieldEventMap, StringFieldLayout, StringFieldModel, strings, texts } from '../../../index'; export class StringField extends BasicField implements StringFieldModel { declare model: StringFieldModel; declare eventMap: StringFieldEventMap; declare self: StringField; declare keyStrokeContext: InputFieldKeyStrokeContext; declare $field: JQuery | JQuery; format: StringFieldFormat; hasAction: boolean; inputMasked: boolean; inputObfuscated: boolean; maxLength: number; maxLengthHandler: MaxLengthHandler; multilineText: boolean; selectionStart: number; selectionEnd: number; selectionTrackingEnabled: boolean; spellCheckEnabled: boolean; trimText: boolean; wrapText: boolean; mouseClicked: boolean; protected _selectionChangingActionHandler: (event: JQuery.TriggeredEvent) => void; constructor() { super(); this.format = null; this.hasAction = false; this.inputMasked = false; this.inputObfuscated = false; this.maxLength = 4000; this.maxLengthHandler = scout.create(MaxLengthHandler, { target: this }); this.multilineText = false; this.selectionStart = -1; this.selectionEnd = -1; this.selectionTrackingEnabled = false; this.spellCheckEnabled = false; this.trimText = true; this.wrapText = false; this._selectionChangingActionHandler = this._onSelectionChangingAction.bind(this); } static Format = { LOWER: 'a' /* IStringField.FORMAT_LOWER */, UPPER: 'A' /* IStringField.FORMAT_UPPER */ } as const; static TRIM_REGEXP = new RegExp('^(\\s*)(.*?)(\\s*)$'); /** * Resolves the text key if value contains one. * This cannot be done in _init because the value field would call _setValue first */ protected override _initValue(value: string) { value = texts.resolveText(value, this.session.locale.languageTag); super._initValue(value); } override _readDisplayText(): string { return this.$field ? this.$field.val() as string : ''; } protected override _initKeyStrokeContext() { super._initKeyStrokeContext(); this.keyStrokeContext.registerKeyStrokes([ new StringFieldEnterKeyStroke(this), new StringFieldCtrlEnterKeyStroke(this) ]); } protected override _createKeyStrokeContext(): InputFieldKeyStrokeContext { return new InputFieldKeyStrokeContext(); } protected override _init(model: InitModelOf) { super._init(model); this._setMultilineText(this.multilineText); } protected override _render() { this.addContainer(this.$parent, 'string-field', new StringFieldLayout(this)); this.addLabel(); this.addMandatoryIndicator(); let $field; if (this.multilineText) { $field = this._makeMultilineField(); this.$container.addClass('multiline'); } else { $field = fields.makeTextField(this.$parent); } $field .on('select', this._selectionChangingActionHandler) .on('mousedown', this._selectionChangingActionHandler) .on('keydown', this._selectionChangingActionHandler) .on('input', this._selectionChangingActionHandler); this.addField($field); this.maxLengthHandler.install($field); this.addStatus(); } protected _makeMultilineField(): JQuery { let $field = this.$parent.makeElement('