mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 01:21:23 +08:00
DEV: Support for onChange
on {{text-field}}
(#9362)
* DEV: Support for `onChange` on `{{text-field}}` This will automatically be debounced and only fired when the value changes. There is also `onChangeImmediate` which is not debounced in case you need that, but in almost all cases when observing text in an element you should debounce. * Add cancel for timer
This commit is contained in:
@ -44,3 +44,43 @@ componentTest("sets the dir attribute to ltr for English text", {
|
||||
assert.equal(find("input").attr("dir"), "ltr");
|
||||
}
|
||||
});
|
||||
|
||||
componentTest("supports onChange", {
|
||||
template: `{{text-field class="tf-test" value=value onChange=changed}}`,
|
||||
beforeEach() {
|
||||
this.called = false;
|
||||
this.newValue = null;
|
||||
this.set("value", "hello");
|
||||
this.set("changed", v => {
|
||||
this.newValue = v;
|
||||
this.called = true;
|
||||
});
|
||||
},
|
||||
async test(assert) {
|
||||
await fillIn(".tf-test", "hello");
|
||||
assert.ok(!this.called);
|
||||
await fillIn(".tf-test", "new text");
|
||||
assert.ok(this.called);
|
||||
assert.equal(this.newValue, "new text");
|
||||
}
|
||||
});
|
||||
|
||||
componentTest("supports onChangeImmediate", {
|
||||
template: `{{text-field class="tf-test" value=value onChangeImmediate=changed}}`,
|
||||
beforeEach() {
|
||||
this.called = false;
|
||||
this.newValue = null;
|
||||
this.set("value", "old");
|
||||
this.set("changed", v => {
|
||||
this.newValue = v;
|
||||
this.called = true;
|
||||
});
|
||||
},
|
||||
async test(assert) {
|
||||
await fillIn(".tf-test", "old");
|
||||
assert.ok(!this.called);
|
||||
await fillIn(".tf-test", "no longer old");
|
||||
assert.ok(this.called);
|
||||
assert.equal(this.newValue, "no longer old");
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user