A platform for community discussion. Free, open, simple.
FEATURE: Use native number fields for integer inputs (#24984)
Ted Johansson8fce890eadac
diff --git a/app/assets/javascripts/discourse/app/components/edit-category-settings.hbs b/app/assets/javascripts/discourse/app/components/edit-category-settings.hbsindex e0ff39b916d..d5d0d6da35a 100644--- a/app/assets/javascripts/discourse/app/components/edit-category-settings.hbs+++ b/app/assets/javascripts/discourse/app/components/edit-category-settings.hbs@@ -5,9 +5,8 @@{{i18n "category.position"}}</label><NumberField- @number={{this.category.position}}+ @value={{this.category.position}}@id="category-position"- @type="number"@min="0"class="position-input"/>@@ -36,9 +35,8 @@{{/if}}</label><NumberField- @number={{this.category.num_featured_topics}}+ @value={{this.category.num_featured_topics}}@id="category-number-featured-topics"- @type="number"@min="1"/></section>@@ -187,9 +185,8 @@{{i18n "category.num_auto_bump_daily"}}</label><NumberField- @number={{this.category.category_setting.num_auto_bump_daily}}+ @value={{this.category.category_setting.num_auto_bump_daily}}@id="category-number-daily-bump"- @type="number"@min="0"/></section>@@ -199,9 +196,8 @@{{i18n "category.auto_bump_cooldown_days"}}</label><NumberField- @number={{this.category.category_setting.auto_bump_cooldown_days}}+ @value={{this.category.category_setting.auto_bump_cooldown_days}}@id="category-auto-bump-cooldown-days"- @type="number"@min="0"/></section>diff --git a/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbs b/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbsindex 06c04f940bc..3fda7840dd3 100644--- a/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbs+++ b/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbs@@ -21,7 +21,7 @@<td><div class="reorder-categories-actions"><NumberField- @number={{readonly category.position}}+ @value={{readonly category.position}}@change={{fn this.change category}}@min="0"/>diff --git a/app/assets/javascripts/discourse/app/components/number-field.hbs b/app/assets/javascripts/discourse/app/components/number-field.hbsnew file mode 100644index 00000000000..c905cebdb2a--- /dev/null+++ b/app/assets/javascripts/discourse/app/components/number-field.hbs@@ -0,0 +1,8 @@+<Input+ id={{@id}}+ class={{@classNames}}+ min={{@min}}+ max={{@max}}+ @type="number"+ @value={{@value}}+/>\ No newline at end of filediff --git a/app/assets/javascripts/discourse/app/components/number-field.js b/app/assets/javascripts/discourse/app/components/number-field.jsdeleted file mode 100644index c5236ca169a..00000000000--- a/app/assets/javascripts/discourse/app/components/number-field.js+++ /dev/null@@ -1,49 +0,0 @@-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";--export default TextField.extend({- classNameBindings: ["invalid"],-- 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) : "";- },-});