/**
* Form field dependency implementation that requires the value of a field to be empty.
*
- * @author Matthias Schmidt
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty
- * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract
- * @since 5.2
+ * @author Matthias Schmidt
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty
+ * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract
+ * @since 5.2
*/
-define(['./Abstract', 'Core'], function (Abstract, Core) {
+define(["require", "exports", "tslib", "./Abstract", "../../../../Core"], function (require, exports, tslib_1, Abstract_1, Core) {
"use strict";
- /**
- * @constructor
- */
- function Empty(dependentElementId, fieldId) {
- this.init(dependentElementId, fieldId);
- }
- ;
- Core.inherit(Empty, Abstract, {
- /**
- * @see WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract#checkDependency
- */
- checkDependency: function () {
+ Abstract_1 = tslib_1.__importDefault(Abstract_1);
+ Core = tslib_1.__importStar(Core);
+ class Empty extends Abstract_1.default {
+ checkDependency() {
if (this._field !== null) {
switch (this._field.tagName) {
- case 'INPUT':
- switch (this._field.type) {
- case 'checkbox':
- return !this._field.checked;
- case 'radio':
+ case "INPUT": {
+ const field = this._field;
+ switch (field.type) {
+ case "checkbox":
+ return !field.checked;
+ case "radio":
if (this._noField && this._noField.checked) {
return true;
}
- return !this._field.checked;
+ return !field.checked;
default:
- return this._field.value.trim().length === 0;
+ return field.value.trim().length === 0;
}
- case 'SELECT':
- if (this._field.multiple) {
- return elBySelAll('option:checked', this._field).length === 0;
+ }
+ case "SELECT": {
+ const field = this._field;
+ if (field.multiple) {
+ return this._field.querySelectorAll("option:checked").length === 0;
}
- return this._field.value == 0 || this._field.value.length === 0;
- case 'TEXTAREA':
+ return field.value == "0" || field.value.length === 0;
+ }
+ case "TEXTAREA": {
return this._field.value.trim().length === 0;
- }
- }
- else {
- for (var i = 0, length = this._fields.length; i < length; i++) {
- if (this._fields[i].checked) {
- return false;
}
}
- return true;
}
+ // Check that none of the fields are checked.
+ return this._fields.every((field) => !field.checked);
}
- });
+ }
+ Core.enableLegacyInheritance(Empty);
return Empty;
});
+++ /dev/null
-/**
- * Form field dependency implementation that requires the value of a field to be empty.
- *
- * @author Matthias Schmidt
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty
- * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract
- * @since 5.2
- */
-define(['./Abstract', 'Core'], function(Abstract, Core) {
- "use strict";
-
- /**
- * @constructor
- */
- function Empty(dependentElementId, fieldId) {
- this.init(dependentElementId, fieldId);
- };
- Core.inherit(Empty, Abstract, {
- /**
- * @see WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract#checkDependency
- */
- checkDependency: function() {
- if (this._field !== null) {
- switch (this._field.tagName) {
- case 'INPUT':
- switch (this._field.type) {
- case 'checkbox':
- return !this._field.checked;
-
- case 'radio':
- if (this._noField && this._noField.checked) {
- return true;
- }
-
- return !this._field.checked;
-
- default:
- return this._field.value.trim().length === 0;
- }
-
- case 'SELECT':
- if (this._field.multiple) {
- return elBySelAll('option:checked', this._field).length === 0;
- }
-
- return this._field.value == 0 || this._field.value.length === 0;
-
- case 'TEXTAREA':
- return this._field.value.trim().length === 0;
- }
- }
- else {
- for (var i = 0, length = this._fields.length; i < length; i++) {
- if (this._fields[i].checked) {
- return false;
- }
- }
-
- return true;
- }
- }
- });
-
- return Empty;
-});
--- /dev/null
+/**
+ * Form field dependency implementation that requires the value of a field to be empty.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty
+ * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract
+ * @since 5.2
+ */
+
+import Abstract from "./Abstract";
+import * as Core from "../../../../Core";
+
+class Empty extends Abstract {
+ public checkDependency(): boolean {
+ if (this._field !== null) {
+ switch (this._field.tagName) {
+ case "INPUT": {
+ const field = this._field as HTMLInputElement;
+ switch (field.type) {
+ case "checkbox":
+ return !field.checked;
+
+ case "radio":
+ if (this._noField && this._noField.checked) {
+ return true;
+ }
+
+ return !field.checked;
+
+ default:
+ return field.value.trim().length === 0;
+ }
+ }
+
+ case "SELECT": {
+ const field = this._field as HTMLSelectElement;
+ if (field.multiple) {
+ return this._field.querySelectorAll("option:checked").length === 0;
+ }
+
+ return field.value == "0" || field.value.length === 0;
+ }
+
+ case "TEXTAREA": {
+ return (this._field as HTMLTextAreaElement).value.trim().length === 0;
+ }
+ }
+ }
+
+ // Check that none of the fields are checked.
+ return this._fields.every((field: HTMLInputElement) => !field.checked);
+ }
+}
+
+Core.enableLegacyInheritance(Empty);
+
+export = Empty;