/** * DevExtreme (ui/editor/editor.js) * Version: 19.1.16 * Build date: Tue Oct 18 2022 * * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; var _string = require("../../core/utils/string"); var $ = require("../../core/renderer"); var dataUtils = require("../../core/element_data"); var Callbacks = require("../../core/utils/callbacks"); var commonUtils = require("../../core/utils/common"); var windowUtils = require("../../core/utils/window"); var Guid = require("../../core/guid"); var getDefaultAlignment = require("../../core/utils/position").getDefaultAlignment; var extend = require("../../core/utils/extend").extend; var Widget = require("../widget/ui.widget"); var ValidationMixin = require("../validation/validation_mixin"); var Overlay = require("../overlay"); var EventsEngine = require("../../events/core/events_engine"); var eventUtils = require("../../events/utils"); var READONLY_STATE_CLASS = "dx-state-readonly"; var INVALID_CLASS = "dx-invalid"; var INVALID_MESSAGE = "dx-invalid-message"; var INVALID_MESSAGE_CONTENT = "dx-invalid-message-content"; var INVALID_MESSAGE_AUTO = "dx-invalid-message-auto"; var INVALID_MESSAGE_ALWAYS = "dx-invalid-message-always"; var VALIDATION_TARGET = "dx-validation-target"; var VALIDATION_MESSAGE_MIN_WIDTH = 100; var READONLY_NAMESPACE = "editorReadOnly"; var Editor = Widget.inherit({ ctor: function() { this.showValidationMessageTimeout = null; this.validationRequest = Callbacks(); this.callBase.apply(this, arguments); var $element = this.$element(); if ($element) { dataUtils.data($element[0], VALIDATION_TARGET, this) } }, _init: function() { this.callBase(); this._initInnerOptionCache("validationTooltipOptions") }, _getDefaultOptions: function() { return extend(this.callBase(), { value: null, name: "", onValueChanged: null, readOnly: false, isValid: true, validationError: null, validationMessageMode: "auto", validationBoundary: void 0, validationMessageOffset: { h: 0, v: 0 }, validationTooltipOptions: {} }) }, _attachKeyboardEvents: function() { if (this.option("readOnly")) { return } this.callBase(); if (this._keyboardProcessor) { this._attachChildKeyboardEvents() } }, _attachChildKeyboardEvents: commonUtils.noop, _setOptionsByReference: function() { this.callBase(); extend(this._optionsByReference, { validationError: true }) }, _createValueChangeAction: function() { this._valueChangeAction = this._createActionByOption("onValueChanged", { excludeValidators: ["disabled", "readOnly"] }) }, _suppressValueChangeAction: function() { this._valueChangeActionSuppressed = true }, _resumeValueChangeAction: function() { this._valueChangeActionSuppressed = false }, _initMarkup: function() { this._toggleReadOnlyState(); this._setSubmitElementName(this.option("name")); this.callBase(); this._renderValidationState() }, _raiseValueChangeAction: function(value, previousValue) { if (!this._valueChangeAction) { this._createValueChangeAction() } this._valueChangeAction(this._valueChangeArgs(value, previousValue)) }, _valueChangeArgs: function(value, previousValue) { return { value: value, previousValue: previousValue, event: this._valueChangeEventInstance } }, _saveValueChangeEvent: function(e) { this._valueChangeEventInstance = e }, _focusInHandler: function(e) { var _this = this; var isValidationMessageShownOnFocus = "auto" === this.option("validationMessageMode"); if (this._canValueBeChangedByClick() && isValidationMessageShownOnFocus) { this._$validationMessage && this._$validationMessage.removeClass(INVALID_MESSAGE_AUTO); clearTimeout(this.showValidationMessageTimeout); this.showValidationMessageTimeout = setTimeout(function() { return _this._$validationMessage && _this._$validationMessage.addClass(INVALID_MESSAGE_AUTO) }, 150) } return this.callBase(e) }, _canValueBeChangedByClick: function() { return false }, _renderValidationState: function() { var isValid = this.option("isValid"); var validationError = this.option("validationError"); var validationMessageMode = this.option("validationMessageMode"); var $element = this.$element(); $element.toggleClass(INVALID_CLASS, !isValid); this.setAria("invalid", !isValid || void 0); if (!windowUtils.hasWindow()) { return } if (this._$validationMessage) { this._$validationMessage.remove(); this.setAria("describedby", null); this._$validationMessage = null } if (!isValid && validationError && validationError.message) { this._$validationMessage = $("