A platform for community discussion. Free, open, simple.
DEV: Introduce a helper for handling events (#25433)
Jarek Radosz36a9b5d0fac5
diff --git a/app/assets/javascripts/admin/addon/components/site-settings/integer.hbs b/app/assets/javascripts/admin/addon/components/site-settings/integer.hbsindex 45e1e0a3e5e..9d77db7c231 100644--- a/app/assets/javascripts/admin/addon/components/site-settings/integer.hbs+++ b/app/assets/javascripts/admin/addon/components/site-settings/integer.hbs@@ -1,5 +1,5 @@<input- {{on "input" (action (mut this.value) value="target.value")}}+ {{on "input" (with-event-value (fn (mut this.value)))}}type="number"value={{this.value}}min={{if this.setting.min this.setting.min null}}diff --git a/app/assets/javascripts/admin/addon/templates/dashboard_reports.hbs b/app/assets/javascripts/admin/addon/templates/dashboard_reports.hbsindex 5187a270090..5aaf148f3f8 100644--- a/app/assets/javascripts/admin/addon/templates/dashboard_reports.hbs+++ b/app/assets/javascripts/admin/addon/templates/dashboard_reports.hbs@@ -6,7 +6,7 @@class="filter-reports-input"placeholder={{i18n "admin.dashboard.filter_reports"}}autofocus={{true}}- {{on "input" (action "filterReports" value="target.value")}}+ {{on "input" (with-event-value this.filterReports)}}/></div>diff --git a/app/assets/javascripts/discourse/app/components/edit-category-settings.hbs b/app/assets/javascripts/discourse/app/components/edit-category-settings.hbsindex a94ba1340ea..a0aa8200792 100644--- a/app/assets/javascripts/discourse/app/components/edit-category-settings.hbs+++ b/app/assets/javascripts/discourse/app/components/edit-category-settings.hbs@@ -5,10 +5,7 @@{{i18n "category.position"}}</label><input- {{on- "input"- (action (mut this.category.position) value="target.value")- }}+ {{on "input" (with-event-value (fn (mut this.category.position)))}}value={{this.category.position}}type="number"min="0"@@ -42,7 +39,7 @@<input{{on"input"- (action (mut this.category.num_featured_topics) value="target.value")+ (with-event-value (fn (mut this.category.num_featured_topics)))}}value={{this.category.num_featured_topics}}type="number"@@ -197,9 +194,8 @@<input{{on"input"- (action- (mut this.category.category_setting.num_auto_bump_daily)- value="target.value"+ (with-event-value+ (fn (mut this.category.category_setting.num_auto_bump_daily)))}}value={{this.category.category_setting.num_auto_bump_daily}}@@ -216,9 +212,8 @@<input{{on"input"- (action- (mut this.category.category_setting.auto_bump_cooldown_days)- value="target.value"+ (with-event-value+ (fn (mut this.category.category_setting.auto_bump_cooldown_days)))}}value={{this.category.category_setting.auto_bump_cooldown_days}}diff --git a/app/assets/javascripts/discourse/app/components/emoji-uploader.hbs b/app/assets/javascripts/discourse/app/components/emoji-uploader.hbsindex 805186c2a99..713977b0ffe 100644--- a/app/assets/javascripts/discourse/app/components/emoji-uploader.hbs+++ b/app/assets/javascripts/discourse/app/components/emoji-uploader.hbs@@ -9,7 +9,7 @@name="name"placeholder={{i18n "admin.emoji.name"}}@value={{readonly this.name}}- {{on "input" (action (mut this.name) value="target.value")}}+ {{on "input" (with-event-value (fn (mut this.name)))}}/></div></div>diff --git a/app/assets/javascripts/discourse/app/components/future-date-input.hbs b/app/assets/javascripts/discourse/app/components/future-date-input.hbsindex c6b3670547e..dd44f926a09 100644--- a/app/assets/javascripts/discourse/app/components/future-date-input.hbs+++ b/app/assets/javascripts/discourse/app/components/future-date-input.hbs@@ -33,7 +33,7 @@class="time-input"@value={{this._time}}disabled={{this.timeInputDisabled}}- {{on "input" (action "onChangeTime" value="target.value")}}+ {{on "input" (with-event-value this.onChangeTime)}}/></div>{{/if}}diff --git a/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbs b/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbsindex ba7e6b4bc97..9b93e0d9239 100644--- a/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbs+++ b/app/assets/javascripts/discourse/app/components/modal/reorder-categories.hbs@@ -22,10 +22,7 @@<td><div class="reorder-categories-actions"><input- {{on- "change"- (action (fn this.change entry) value="target.value")- }}+ {{on "change" (with-event-value (fn this.change entry))}}value={{entry.position}}type="number"min="0"diff --git a/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.hbs b/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.hbsindex d1ee793eaa5..fbec1f648fa 100644--- a/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.hbs+++ b/app/assets/javascripts/discourse/app/components/modal/sidebar-section-form.hbs@@ -21,7 +21,7 @@id="section-name"{{on"input"- (action (mut this.transformedModel.title) value="target.value")+ (with-event-value (fn (mut this.transformedModel.title)))}}/>diff --git a/app/assets/javascripts/discourse/app/components/number-field.js b/app/assets/javascripts/discourse/app/components/number-field.jsindex 72e393c48a4..d9df7fb93a3 100644--- a/app/assets/javascripts/discourse/app/components/number-field.js+++ b/app/assets/javascripts/discourse/app/components/number-field.js@@ -10,7 +10,7 @@ export default TextField.extend({init() {this._super(...arguments);deprecated(- `NumberField component is deprecated. Use native <input> elements instead.\ne.g. <input {{on "input" (action (mut this.value) value="target.value")}} type="number" value={{this.value}} />`,+ `NumberField component is deprecated. Use native <input> elements instead.\ne.g. <input {{on "input" (with-event-value (fn (mut this.value)))}} type="number" value={{this.value}} />`,{id: "discourse.number-field",since: "3.2.0.beta5",diff --git a/app/assets/javascripts/discourse/app/components/search-advanced-options.hbs b/app/assets/javascripts/discourse/app/components/search-advanced-options.hbsindex 1ed7b7a850d..4dea66359ce 100644--- a/app/assets/javascripts/discourse/app/components/search-advanced-options.hbs+++ b/app/assets/javascripts/discourse/app/components/search-advanced-options.hbs@@ -246,10 +246,7 @@id="search-min-post-count"placeholder={{i18n "search.advanced.post.min.placeholder"}}aria-label={{i18n "search.advanced.post.min.aria_label"}}- {{on- "input"- (action "onChangeSearchTermMinPostCount" value="target.value")- }}+ {{on "input" (with-event-value this.onChangeSearchTermMinPostCount)}}/>{{d-icon "arrows-alt-h"}}<Input@@ -259,10 +256,7 @@id="search-max-post-count"placeholder={{i18n "search.advanced.post.max.placeholder"}}aria-label={{i18n "search.advanced.post.max.aria_label"}}- {{on- "input"- (action "onChangeSearchTermMaxPostCount" value="target.value")- }}+ {{on "input" (with-event-value this.onChangeSearchTermMaxPostCount)}}/></div></div>@@ -278,10 +272,7 @@id="search-min-views"placeholder={{i18n "search.advanced.min_views.placeholder"}}aria-label={{i18n "search.advanced.min_views.aria_label"}}- {{on- "input"- (action "onChangeSearchTermMinViews" value="target.value")- }}+ {{on "input" (with-event-value this.onChangeSearchTermMinViews)}}/>{{d-icon "arrows-alt-h"}}<Input@@ -291,10 +282,7 @@id="search-max-views"placeholder={{i18n "search.advanced.max_views.placeholder"}}aria-label={{i18n "search.advanced.max_views.aria_label"}}- {{on- "input"- (action "onChangeSearchTermMaxViews" value="target.value")- }}+ {{on "input" (with-event-value this.onChangeSearchTermMaxViews)}}/></div></div>diff --git a/app/assets/javascripts/discourse/app/components/sidebar/section-form-link.hbs b/app/assets/javascripts/discourse/app/components/sidebar/section-form-link.hbsindex 8e22a47ed09..3887345c3b1 100644--- a/app/assets/javascripts/discourse/app/components/sidebar/section-form-link.hbs+++ b/app/assets/javascripts/discourse/app/components/sidebar/section-form-link.hbs@@ -47,7 +47,7 @@@value={{@link.name}}class={{@link.nameCssClass}}ariaLabel={{i18n "sidebar.sections.custom.links.name.label"}}- {{on "input" (action (mut @link.name) value="target.value")}}+ {{on "input" (with-event-value (fn (mut @link.name)))}}/>{{#if @link.invalidNameMessage}}<div class="name warning">@@ -62,7 +62,7 @@@value={{@link.value}}class={{@link.valueCssClass}}ariaLabel={{i18n "sidebar.sections.custom.links.value.label"}}- {{on "input" (action (mut @link.value) value="target.value")}}+ {{on "input" (with-event-value (fn (mut @link.value)))}}/>{{#if @link.invalidValueMessage}}<div class="value warning">diff --git a/app/assets/javascripts/discourse/app/components/tag-info.hbs b/app/assets/javascripts/discourse/app/components/tag-info.hbsindex f8773bc0375..d7d944bd9de 100644--- a/app/assets/javascripts/discourse/app/components/tag-info.hbs+++ b/app/assets/javascripts/discourse/app/components/tag-info.hbs@@ -7,7 +7,7 @@@id="edit-name"@value={{readonly this.tagInfo.name}}@maxlength={{this.siteSettings.max_tag_length}}- @input={{action (mut this.newTagName) value="target.value"}}+ @input={{with-event-value (fn (mut this.newTagName))}}@autofocus="true"/>@@ -16,10 +16,7 @@@value={{readonly this.tagInfo.descriptionWithNewLines}}placeholder={{i18n "tagging.description"}}maxlength={{1000}}- {{on- "input"- (action (mut this.newTagDescription) value="target.value")- }}+ {{on "input" (with-event-value (fn (mut this.newTagDescription)))}}autofocus="true"/>diff --git a/app/assets/javascripts/discourse/app/helpers/with-event-value.js b/app/assets/javascripts/discourse/app/helpers/with-event-value.jsnew file mode 100644index 00000000000..24b88a576d7--- /dev/null+++ b/app/assets/javascripts/discourse/app/helpers/with-event-value.js@@ -0,0 +1,7 @@+import { get } from "@ember/object";++export default function withEventValue(mutFn) {+ return function (event) {+ return mutFn(get(event, "target.value"));+ };+}diff --git a/app/assets/javascripts/discourse/app/templates/groups/index.hbs b/app/assets/javascripts/discourse/app/templates/groups/index.hbsindex 38dc2b31104..fe1af8e43ce 100644--- a/app/assets/javascripts/discourse/app/templates/groups/index.hbs+++ b/app/assets/javascripts/discourse/app/templates/groups/index.hbs@@ -22,7 +22,7 @@@value={{readonly this.filter}}placeholder={{i18n "groups.index.all"}}class="groups-header-filters-name no-blur"- {{on "input" (action "onFilterChanged" value="target.value")}}+ {{on "input" (with-event-value this.onFilterChanged)}}@type="search"aria-description={{i18n "groups.index.search_results"}}/>diff --git a/app/assets/javascripts/discourse/app/templates/users.hbs b/app/assets/javascripts/discourse/app/templates/users.hbsindex 93fb9b8f72e..e5c0aa2dc97 100644--- a/app/assets/javascripts/discourse/app/templates/users.hbs+++ b/app/assets/javascripts/discourse/app/templates/users.hbs@@ -41,10 +41,7 @@@value={{readonly this.nameInput}}placeholder={{i18n "directory.filter_name"}}class="filter-name no-blur"- {{on- "input"- (action "onUsernameFilterChanged" value="target.value")- }}+ {{on "input" (with-event-value this.onUsernameFilterChanged)}}/>{{#if this.showGroupFilter}}<ComboBoxdiff --git a/app/assets/javascripts/discourse/tests/integration/components/char-counter-test.js b/app/assets/javascripts/discourse/tests/integration/components/char-counter-test.jsindex ca845731964..705826871a8 100644--- a/app/assets/javascripts/discourse/tests/integration/components/char-counter-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/char-counter-test.js@@ -20,9 +20,14 @@ module("Integration | Component | char-counter", function (hooks) {test("updating value updates counter", async function (assert) {this.max = 50;- await render(- hbs`<CharCounter @value={{this.charCounterContent}} @max={{this.max}}><textarea {{on "input" (action (mut this.charCounterContent) value="target.value")}}></textarea></CharCounter>`- );+ await render(hbs`+ <CharCounter+ @value={{this.charCounterContent}}+ @max={{this.max}}+ >+ <textarea {{on "input" (with-event-value (fn (mut this.charCounterContent)))}}></textarea>+ </CharCounter>+ `);assert.dom(this.element)diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-emoji-picker.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-emoji-picker.hbsindex a2040ffb06e..0353a804e31 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-emoji-picker.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-emoji-picker.hbs@@ -25,7 +25,7 @@)}}@value={{this.chatEmojiPickerManager.picker.initialFilter}}- @filterAction={{action this.didInputFilter value="target.value"}}+ @filterAction={{with-event-value this.didInputFilter}}@icons={{hash left="search"}}@containerClass="chat-emoji-picker__filter"autofocus={{true}}diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.hbsindex cd30124048e..39e2eaeb57b 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.hbs@@ -17,7 +17,7 @@class="chat-modal-create-channel__input"@type="text"@value={{this.name}}- {{on "input" (action this.onNameChange value="target.value")}}+ {{on "input" (with-event-value this.onNameChange)}}/></div>diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-description.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-description.hbsindex f3d22acaa11..b2f0e08fe84 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-description.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-description.hbs@@ -14,10 +14,7 @@@max={{this.descriptionMaxLength}}><textarea- {{on- "input"- (action this.onChangeChatChannelDescription value="target.value")- }}+ {{on "input" (with-event-value this.onChangeChatChannelDescription)}}class="chat-modal-edit-channel-description__description-input"placeholder={{i18n"chat.channel_edit_description_modal.input_placeholder"diff --git a/plugins/styleguide/assets/javascripts/discourse/components/sections/molecules/char-counter.hbs b/plugins/styleguide/assets/javascripts/discourse/components/sections/molecules/char-counter.hbsindex a03a141bb92..693fb3805f1 100644--- a/plugins/styleguide/assets/javascripts/discourse/components/sections/molecules/char-counter.hbs+++ b/plugins/styleguide/assets/javascripts/discourse/components/sections/molecules/char-counter.hbs@@ -1,10 +1,7 @@<StyleguideExample @title="<CharCounter>"><CharCounter @max="50" @value={{@dummy.charCounterContent}}><textarea- {{on- "input"- (action (mut @dummy.charCounterContent) value="target.value")- }}+ {{on "input" (with-event-value (fn (mut @dummy.charCounterContent)))}}class="styleguide--char-counter"></textarea></CharCounter>