Skip to content

Commit

Permalink
fix: call on-update hook correctly (#641)
Browse files Browse the repository at this point in the history
This fixes a regression introduced with the update to glimmer.
  • Loading branch information
czosel committed Jul 21, 2021
1 parent 5b20162 commit b8688b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions addon/components/validated-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export class ValidatedInput extends Component {

@action
update(value) {
if (this["on-update"]) {
this["on-update"](value, this.args.model);
if (this.args["on-update"]) {
this.args["on-update"](value, this.args.model);
} else {
this.args.model.set
? this.args.model.set(this.args.name, value)
Expand Down
2 changes: 1 addition & 1 deletion testem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
test_page: "tests/index.html?hidepassed",
disable_watching: true,
launch_in_ci: ["Chrome"],
launch_in_dev: ["Chrome"],
launch_in_dev: [],
browser_start_timeout: 120,
browser_args: {
Chrome: {
Expand Down
16 changes: 15 additions & 1 deletion tests/integration/components/validated-input-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, click, settled } from "@ember/test-helpers";
import { render, click, fillIn, settled } from "@ember/test-helpers";
import Changeset from "ember-changeset";
import { hbs } from "ember-cli-htmlbars";
import { setupRenderingTest } from "ember-qunit";
Expand Down Expand Up @@ -52,6 +52,20 @@ module("Integration | Component | validated input", function (hooks) {
assert.dom("input").hasValue("Max");
});

test("it calls on-update if given", async function (assert) {
this.set("model", new Changeset({ firstName: "Max" }));
this.set("update", (value, changeset) => {
changeset.set("firstName", value.toUpperCase());
});
await render(
hbs`{{validated-input name="firstName" model=model on-update=update}}`
);

await fillIn("input", "foo");

assert.dom("input").hasValue("FOO");
});

test("it renders inputs with value even if model is defined", async function (assert) {
this.set("model", new Changeset({ firstName: "Max" }));

Expand Down

0 comments on commit b8688b6

Please sign in to comment.