Skip to content

Commit

Permalink
fix: incorporate review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabauke committed Dec 19, 2023
1 parent 41404a7 commit f87a06f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
5 changes: 2 additions & 3 deletions packages/form/addon/components/cf-field/input/radio.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
{{/if}}
</label>
{{/each}}
{{#if (and (eq @field.question.raw.isRequired "false") @field.answer.value)}}
{{#if (and @field.optional @field.answer.value)}}
<br />
<a data-test-radio-reset href="#" {{on "click" (fn @onSave null)}}>{{t
<a href="" data-test-radio-reset {{on "click" this.reset}}>{{t
"caluma.form.power-select.reset"
}}</a>

{{/if}}
11 changes: 11 additions & 0 deletions packages/form/addon/components/cf-field/input/radio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { action } from "@ember/object";
import Component from "@glimmer/component";

export default class CfFieldInpuRadio extends Component {
@action
reset(event) {
event.preventDefault();

this.args.onSave(null);
}
}
1 change: 0 additions & 1 deletion packages/form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ember-math-helpers": "^4.0.0",
"ember-power-select": "^7.2.0",
"ember-resources": "^6.4.2",
"ember-truth-helpers": "^4.0.3",
"ember-uikit": "^9.0.0",
"ember-validators": "^4.1.2",
"graphql": "^15.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,28 @@ module("Integration | Component | cf-field/input/radio", function (hooks) {

test("it triggers save on click", async function (assert) {
this.set("value", false);
this.set("raw", { isRequired: "false" });
this.set("optional", true);
this.set("onSave", (value) => {
this.set("value", value);
assert.step("save");
});

await render(hbs`<CfField::Input::Radio
@onSave={{this.onSave}}
@field={{hash
options=(array (hash slug="option-1" label="Option 1"))
answer=(hash value=this.value)
question=(hash __typename="ChoiceQuestion" slug="test" raw=this.raw)
}}
/>`);
@onSave={{this.onSave}}
@field={{hash
options=(array (hash slug="option-1" label="Option 1"))
answer=(hash value=this.value)
question=(hash __typename="ChoiceQuestion" slug="test" )
optional=this.optional
}}
/>`);

await click("label:nth-of-type(1) input");
await click("[data-test-radio-reset]");

assert.verifySteps(["save", "save"]);

this.set("raw", { isRequired: "true" });
this.set("optional", false);
await click("label:nth-of-type(1) input");

assert.verifySteps(["save"]);
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f87a06f

Please sign in to comment.