--- /dev/null
+require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/ValueInterval'], ({ ValueInterval }) => {
+ // dependency '{@$dependency->getId()}'
+ new ValueInterval(
+ '{@$dependency->getDependentNode()->getPrefixedId()}Container',
+ '{@$dependency->getField()->getPrefixedId()}'
+ )
+ .minimum({if $dependency->getMinimum() !== null}{@$dependency->getMinimum()}{else}null{/if})
+ .maximum({if $dependency->getMaximum() !== null}{@$dependency->getMaximum()}{else}null{/if});
+});
--- /dev/null
+/**
+ * Form field dependency implementation that requires the value of a field to be in the interval
+ * [minimum, maximum].
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/ValueInterval
+ * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract
+ * @since 5.5
+ */
+
+import Abstract from "./Abstract";
+import * as DependencyManager from "./Manager";
+
+export class ValueInterval extends Abstract {
+ protected _maximum: number | null = null;
+ protected _minimum: number | null = null;
+
+ checkDependency(): boolean {
+ if (this._field) {
+ if (DependencyManager.isHiddenByDependencies(this._field)) {
+ return false;
+ }
+
+ const value = parseFloat((this._field as HTMLInputElement).value);
+ if (isNaN(value)) {
+ return false;
+ }
+
+ if (this._minimum !== null && this._minimum > value) {
+ return false;
+ } else if (this._maximum !== null && this._maximum < value) {
+ return false;
+ }
+
+ return true;
+ } else {
+ throw new Error("'ValueInterval' is only supported for individual fields.");
+ }
+ }
+
+ /**
+ * Sets the maximum value of the value interval or unsets the maximum value if `null` is given.
+ */
+ maximum(maximum: number | null): ValueInterval {
+ this._maximum = maximum;
+
+ return this;
+ }
+
+ /**
+ * Sets the minimum value of the value interval or unsets the minimum value if `null` is given.
+ */
+ minimum(minimum: number | null): ValueInterval {
+ this._minimum = minimum;
+
+ return this;
+ }
+}
+
+export default ValueInterval;
--- /dev/null
+require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/ValueInterval'], ({ ValueInterval }) => {
+ // dependency '{@$dependency->getId()}'
+ new ValueInterval(
+ '{@$dependency->getDependentNode()->getPrefixedId()}Container',
+ '{@$dependency->getField()->getPrefixedId()}'
+ )
+ .minimum({if $dependency->getMinimum() !== null}{@$dependency->getMinimum()}{else}null{/if})
+ .maximum({if $dependency->getMaximum() !== null}{@$dependency->getMaximum()}{else}null{/if});
+});
--- /dev/null
+/**
+ * Form field dependency implementation that requires the value of a field to be in the interval
+ * [minimum, maximum].
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/ValueInterval
+ * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract
+ * @since 5.5
+ */
+define(["require", "exports", "tslib", "./Abstract", "./Manager"], function (require, exports, tslib_1, Abstract_1, DependencyManager) {
+ "use strict";
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.ValueInterval = void 0;
+ Abstract_1 = tslib_1.__importDefault(Abstract_1);
+ DependencyManager = tslib_1.__importStar(DependencyManager);
+ class ValueInterval extends Abstract_1.default {
+ constructor() {
+ super(...arguments);
+ this._maximum = null;
+ this._minimum = null;
+ }
+ checkDependency() {
+ if (this._field) {
+ if (DependencyManager.isHiddenByDependencies(this._field)) {
+ return false;
+ }
+ const value = parseFloat(this._field.value);
+ if (isNaN(value)) {
+ return false;
+ }
+ if (this._minimum !== null && this._minimum > value) {
+ return false;
+ }
+ else if (this._maximum !== null && this._maximum < value) {
+ return false;
+ }
+ return true;
+ }
+ else {
+ throw new Error("'ValueInterval' is only supported for individual fields.");
+ }
+ }
+ /**
+ * Sets the maximum value of the value interval or unsets the maximum value if `null` is given.
+ */
+ maximum(maximum) {
+ this._maximum = maximum;
+ return this;
+ }
+ /**
+ * Sets the minimum value of the value interval or unsets the minimum value if `null` is given.
+ */
+ minimum(minimum) {
+ this._minimum = minimum;
+ return this;
+ }
+ }
+ exports.ValueInterval = ValueInterval;
+ exports.default = ValueInterval;
+});
--- /dev/null
+<?php
+
+namespace wcf\system\form\builder\field\dependency;
+
+/**
+ * Represents a dependency that requires the value of a field to be in the interval
+ * [minimum, maximum].
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Form\Builder\Field\Dependency
+ * @since 5.5
+ */
+final class ValueIntervalFormFieldDependency extends AbstractFormFieldDependency
+{
+ /**
+ * maximum value of the value interval
+ */
+ protected $maximum;
+
+ /**
+ * minimum value of the value interval
+ */
+ protected $minimum;
+
+ /**
+ * @inheritDoc
+ */
+ protected $templateName = '__valueIntervalFormFieldDependency';
+
+ /**
+ * @inheritDoc
+ */
+ public function checkDependency()
+ {
+ $value = $this->getField()->getValue();
+ if (!\is_numeric($value)) {
+ return false;
+ }
+
+ $value = \floatval($value);
+
+ if ($this->minimum !== null && $this->minimum > $value) {
+ return false;
+ } elseif ($this->maximum !== null && $this->maximum < $value) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns the maximum value of the value interval or `null` if no maximum has been set.
+ */
+ public function getMaximum(): ?float
+ {
+ return $this->maximum;
+ }
+
+ /**
+ * Returns the minimum value of the value interval or `null` if no minimum has been set.
+ */
+ public function getMinimum(): ?float
+ {
+ return $this->minimum;
+ }
+
+ /**
+ * Sets the maximum value of the value interval or unsets the maximum value if `null` is given.
+ */
+ public function maximum(?float $maximum = null): self
+ {
+ if ($maximum !== null && $this->minimum !== null && $maximum < $this->minimum) {
+ throw new \InvalidArgumentException(
+ "Maximum value '{$maximum}' for dependency '{$this->getId()}' is less than set minimum value '{$this->minimum}'."
+ );
+ }
+
+ $this->maximum = $maximum;
+
+ return $this;
+ }
+
+ /**
+ * Sets the minimum value of the value interval or unsets the minimum value if `null` is given.
+ */
+ public function minimum(?float $minimum = null): self
+ {
+ if ($minimum !== null && $this->maximum !== null && $minimum > $this->maximum) {
+ throw new \InvalidArgumentException(
+ "Minimum value '{$minimum}' for dependency '{$this->getId()}' is greater than set maximum value '{$this->maximum}'."
+ );
+ }
+
+ $this->minimum = $minimum;
+
+ return $this;
+ }
+}