Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call on-update hook correctly #641

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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