+
+
+
+ {{htmlSafe @setting.description}}
+
+}
diff --git a/app/assets/javascripts/admin/addon/mixins/setting-component.js b/app/assets/javascripts/admin/addon/mixins/setting-component.js
index ab24c65993f..bb7b8e66317 100644
--- a/app/assets/javascripts/admin/addon/mixins/setting-component.js
+++ b/app/assets/javascripts/admin/addon/mixins/setting-component.js
@@ -33,6 +33,7 @@ const CUSTOM_TYPES = [
"simple_list",
"emoji_list",
"named_list",
+ "file_size_restriction",
];
const AUTO_REFRESH_ON_SAVE = ["logo", "logo_small", "large_icon"];
diff --git a/app/assets/javascripts/discourse/app/components/number-field.js b/app/assets/javascripts/discourse/app/components/number-field.js
index 38838358ef8..c5236ca169a 100644
--- a/app/assets/javascripts/discourse/app/components/number-field.js
+++ b/app/assets/javascripts/discourse/app/components/number-field.js
@@ -1,36 +1,13 @@
import TextField from "discourse/components/text-field";
+import { allowOnlyNumericInput } from "discourse/lib/utilities";
import discourseComputed from "discourse-common/utils/decorators";
import I18n from "discourse-i18n";
-const ALLOWED_KEYS = [
- "Enter",
- "Backspace",
- "Tab",
- "Delete",
- "ArrowLeft",
- "ArrowUp",
- "ArrowRight",
- "ArrowDown",
- "0",
- "1",
- "2",
- "3",
- "4",
- "5",
- "6",
- "7",
- "8",
- "9",
-];
-
export default TextField.extend({
classNameBindings: ["invalid"],
keyDown: function (event) {
- return (
- ALLOWED_KEYS.includes(event.key) ||
- (event.key === "-" && this._minNumber && this._minNumber < 0)
- );
+ allowOnlyNumericInput(event, this._minNumber && this._minNumber < 0);
},
get _minNumber() {
diff --git a/app/assets/javascripts/discourse/app/lib/utilities.js b/app/assets/javascripts/discourse/app/lib/utilities.js
index 1b5903f045b..f666147a2a1 100644
--- a/app/assets/javascripts/discourse/app/lib/utilities.js
+++ b/app/assets/javascripts/discourse/app/lib/utilities.js
@@ -693,3 +693,34 @@ export function tokenRange(tokens, start, end) {
return contents;
}
+
+export function allowOnlyNumericInput(event, allowNegative = false) {
+ const ALLOWED_KEYS = [
+ "Enter",
+ "Backspace",
+ "Tab",
+ "Delete",
+ "ArrowLeft",
+ "ArrowUp",
+ "ArrowRight",
+ "ArrowDown",
+ "0",
+ "1",
+ "2",
+ "3",
+ "4",
+ "5",
+ "6",
+ "7",
+ "8",
+ "9",
+ ];
+
+ if (!ALLOWED_KEYS.includes(event.key)) {
+ if (allowNegative && event.key === "-") {
+ return;
+ } else {
+ event.preventDefault();
+ }
+ }
+}
diff --git a/app/assets/javascripts/discourse/tests/integration/components/file-size-input-test.js b/app/assets/javascripts/discourse/tests/integration/components/file-size-input-test.js
new file mode 100644
index 00000000000..1305c3e9d91
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/integration/components/file-size-input-test.js
@@ -0,0 +1,128 @@
+import { click, fillIn, render } from "@ember/test-helpers";
+import { hbs } from "ember-cli-htmlbars";
+import { module, test } from "qunit";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
+
+module("Integration | Component | file-size-input", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("file size unit selector kb", async function (assert) {
+ this.set("value", 1024);
+ this.set("max", 4096);
+ this.set("onChangeSize", () => {});
+ this.set("updateValidationMessage", () => {});
+
+ await render(hbs`
+