diff --git a/app/assets/javascripts/admin/addon/components/site-settings/integer.hbs b/app/assets/javascripts/admin/addon/components/site-settings/integer.hbs index 21881b18eea..873f9bc1bfb 100644 --- a/app/assets/javascripts/admin/addon/components/site-settings/integer.hbs +++ b/app/assets/javascripts/admin/addon/components/site-settings/integer.hbs @@ -1,8 +1,9 @@ - diff --git a/app/assets/javascripts/discourse/app/components/edit-category-settings.hbs b/app/assets/javascripts/discourse/app/components/edit-category-settings.hbs index d5d0d6da35a..a94ba1340ea 100644 --- a/app/assets/javascripts/discourse/app/components/edit-category-settings.hbs +++ b/app/assets/javascripts/discourse/app/components/edit-category-settings.hbs @@ -4,10 +4,15 @@ - @@ -34,10 +39,15 @@ {{i18n "category.num_featured_topics"}} {{/if}} - @@ -184,10 +194,18 @@ - @@ -195,10 +213,18 @@ - diff --git a/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbs b/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbs index 3fda7840dd3..fea2d492637 100644 --- a/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbs +++ b/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbs @@ -20,10 +20,14 @@
- \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/number-field.js b/app/assets/javascripts/discourse/app/components/number-field.js new file mode 100644 index 00000000000..72e393c48a4 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/number-field.js @@ -0,0 +1,62 @@ +import TextField from "discourse/components/text-field"; +import { allowOnlyNumericInput } from "discourse/lib/utilities"; +import deprecated from "discourse-common/lib/deprecated"; +import discourseComputed from "discourse-common/utils/decorators"; +import I18n from "discourse-i18n"; + +export default TextField.extend({ + classNameBindings: ["invalid"], + + init() { + this._super(...arguments); + deprecated( + `NumberField component is deprecated. Use native elements instead.\ne.g. `, + { + id: "discourse.number-field", + since: "3.2.0.beta5", + dropFrom: "3.3.0", + } + ); + }, + + keyDown: function (event) { + allowOnlyNumericInput(event, this._minNumber && this._minNumber < 0); + }, + + get _minNumber() { + if (!this.get("min")) { + return; + } + return parseInt(this.get("min"), 10); + }, + + get _maxNumber() { + if (!this.get("max")) { + return; + } + return parseInt(this.get("max"), 10); + }, + + @discourseComputed("number") + value: { + get(number) { + return parseInt(number, 10); + }, + set(value) { + const num = parseInt(value, 10); + if (isNaN(num)) { + this.set("invalid", true); + return value; + } else { + this.set("invalid", false); + this.set("number", num); + return num.toString(); + } + }, + }, + + @discourseComputed("placeholderKey") + placeholder(key) { + return key ? I18n.t(key) : ""; + }, +}); diff --git a/app/assets/javascripts/discourse/tests/integration/components/number-field-test.js b/app/assets/javascripts/discourse/tests/integration/components/number-field-test.js index 9c12e71fc44..2141eb4f9fb 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/number-field-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/number-field-test.js @@ -2,6 +2,7 @@ import { fillIn, render, triggerKeyEvent } from "@ember/test-helpers"; import { hbs } from "ember-cli-htmlbars"; import { module, test } from "qunit"; import { setupRenderingTest } from "discourse/tests/helpers/component-test"; +import { withSilencedDeprecationsAsync } from "discourse-common/lib/deprecated"; module("Integration | Component | number-field", function (hooks) { setupRenderingTest(hooks); @@ -9,9 +10,11 @@ module("Integration | Component | number-field", function (hooks) { test("number field", async function (assert) { this.set("value", 123); - await render(hbs` - - `); + await withSilencedDeprecationsAsync("discourse.number-field", async () => { + await render(hbs` + + `); + }); await fillIn(".number-field-test", "33"); @@ -34,9 +37,11 @@ module("Integration | Component | number-field", function (hooks) { test("number field | min value", async function (assert) { this.set("value", ""); - await render(hbs` - - `); + await withSilencedDeprecationsAsync("discourse.number-field", async () => { + await render(hbs` + + `); + }); await triggerKeyEvent(".number-field-test", "keydown", 189); // - await triggerKeyEvent(".number-field-test", "keydown", 49); // 1 @@ -47,9 +52,11 @@ module("Integration | Component | number-field", function (hooks) { "value is cleared when the input is less than the min" ); - await render(hbs` - - `); + await withSilencedDeprecationsAsync("discourse.number-field", async () => { + await render(hbs` + + `); + }); await fillIn(".number-field-test", "-1"); diff --git a/app/assets/javascripts/discourse/tests/unit/components/reorder-categories-test.js b/app/assets/javascripts/discourse/tests/unit/components/reorder-categories-test.js index 941a44a1b02..e0d604845c1 100644 --- a/app/assets/javascripts/discourse/tests/unit/components/reorder-categories-test.js +++ b/app/assets/javascripts/discourse/tests/unit/components/reorder-categories-test.js @@ -94,7 +94,7 @@ module("Unit | Component | reorder-categories", function (hooks) { site.set("categories", [elem1, elem2, elem3]); // Move category 'foo' from position 0 to position 2 - component.change(elem1, { target: { value: "2" } }); + component.change(elem1, "2"); assert.deepEqual(component.categoriesOrdered.mapBy("slug"), [ "bar", @@ -137,7 +137,7 @@ module("Unit | Component | reorder-categories", function (hooks) { const site = getOwner(this).lookup("service:site"); site.set("categories", [elem1, child1, elem2, elem3]); - component.change(elem1, { target: { value: 3 } }); + component.change(elem1, "3"); assert.deepEqual(component.categoriesOrdered.mapBy("slug"), [ "bar",